简体   繁体   English

如何在nodeJS中格式化iso日期

[英]How to format iso date in nodeJS

Here is my code这是我的代码

var newDateObj2 = moment("2020-04-29T14:05:00.000Z").format('YY/MM/DD,HH:mm:ss.S');
console.log(newDateObj2);

Output 
20/04/29,19:35:00.0

Expected Output
20/04/29,14:05:00.0

Why 5.30 (h.mm) getting added in my final result, When i print为什么在我的最终结果中添加了 5.30 (h.mm),当我打印时

moment("2020-04-29T14:05:00.000Z")`=> Moment<2020-04-29T19:35:00+05:30>

How to get Output 20/04/29,14:05:00.0如何获得 Output 20/04/29,14:05:00.0

You should trim the Z from the ISO date string or use the utc() function moment("2020-04-29T14:06:00.000Z").utc().format('YY/MM/DD,HH:mm:ss.S');您应该从 ISO 日期字符串中修剪 Z 或使用 utc() function moment("2020-04-29T14:06:00.000Z").utc().format('YY/MM/DD,HH:mm: ss.S');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM