首页 > 解决方案 > 将日期从任何其他格式转换为 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'

标签: javascript

解决方案


使用 Moment.js 库http://momentjs.com/它会为你省去很多麻烦。

moment().format('DDMMMYYYY');

推荐阅读