javascript - 将日期从任何其他格式转换为 DDMMYYYY
问题描述
将日期从任何其他格式转换为 DDMMYYYY
var date = new Date("2019/12/27"),
yr = date.getFullYear(),
month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(),
day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(),
newDate = yr + '-' + month + '-' + day;
我试过这样,但它不接受'27/12/2019'
解决方案
使用 Moment.js 库http://momentjs.com/它会为你省去很多麻烦。
moment().format('DDMMMYYYY');
推荐阅读
- file - java.io.File 的 .createNewFile() 不会创建文件
- python - OpenCV:跟踪扩展矩形的坐标
- ios - 颤动的iOS功能背景模式已打开
- javascript - 如何在 Angular 5 规范中为 document.URL 编写单元测试
- python - 在 Django 应用程序中显示特定用户详细信息而不是所有详细信息
- ios - Xcode for Swift 4 中的屏幕时间报告
- c - 从 ARP 数据包打印源和目标 IP 地址
- raku - Perl 6:使用 AT-POS 的可写多维下标访问
- text - 使用记事本删除/或替换为空格->所有字符串以及其中的内容
- javascript - 从 html 调用一个弹出的 javascript