[英]Convert DD-MM-YYYY format to MM-DD-YYYY in moment.js
I am trying to convert a date from DD-MM-YYYY to MM-DD-YYYY .我正在尝试将日期从DD-MM-YYYY 转换为MM-DD-YYYY 。 But it doesn't work for me.但这对我不起作用。 I tried this我试过这个
var test = Date.parse('15-06-2010'); var SearchDate = moment('15-06-2010').format("MM-DD-YYYY"); var day = moment(new Date("15-06-2010"), "MM-DD-YYYY"); console.log(test); console.log(day);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.5.1/moment.min.js"></script>
Help me.帮帮我。
Try this:试试这个:
var date = moment('15-06-2010', 'DD-MM-YYYY')
console.log(date.format('MM-DD-YYYY'))
You have to specify the input format for the date when parsing a date with momentjs.使用momentjs解析日期时必须指定日期的输入格式。
Here 26-11-2019 will be converted to 11-26-2019这里 26-11-2019 将转换为 11-26-2019
const date = moment('26-11-2019','DD-MM-YYYY').format('MM-DD-YYYY');
To the format method we can give any format, how you want the output.对于格式方法,我们可以给出任何格式,您想要的输出方式。
试试这个:
moment(moment('15-06-2010', 'DD-MM-YYYY')).format('MM-DD-YYYY')
I have to validate the date using momentjs.我必须使用 momentjs 验证日期。 So following works for me :).所以以下对我有用:)。
var dateValidate = moment(startDate).isValid() || moment(startDate, "DD/MM/YYYY").isValid() ? true : false;
Try something like this,尝试这样的事情,
var formatDate= 1399919400000;
var responseDate = moment(formatDate).format('MM-DD-YYYY');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.