[英]Format MomentJS Date Output
Trying to format a date in an application I'm working on to:尝试在我正在处理的应用程序中格式化日期:
// Example format: YYYY-MM-DDTHH:mm:ss.SSSZ
// Example: 2021-09-25T00:00:00.000Z
let date: Moment;
date.format('YYYY-MM-DDTHH:mm:ss.SSSZ');
Formatting this date variable returns the below:格式化此日期变量会返回以下内容:
2021-09-25T00:00:00.000+00:00
How can I remove those trailing zeros after the milliseconds & the plus sign?如何在毫秒和加号之后删除那些尾随零? Essentially, everything after the plus sign including the plus like the below:基本上,加号之后的所有内容包括加号,如下所示:
2021-09-25T00:00:00.000Z
Thanks in advance for the help!在此先感谢您的帮助!
You can simply remove those options ..您可以简单地删除这些选项..
date.format('YYYY-MM-DD');
Or to remove anything beyond just the plus sign ..或者删除除加号以外的任何内容..
date.format('YYYY-MM-DDTHH:mm:ss');
UPDATE更新
If you want the fractional of 3 IE .999
Then use three capital "S" - SSS
And lose the "Z" which is your offset
-- +00:00
如果你想要 3 IE .999
的小数然后使用三个大写的“S” - SSS
并失去作为你的offset
的“Z” - +00:00
date.format('YYYY-MM-DDTHH:mm:ss.SSS')
The documentation can be found HERE文档可以在这里找到
SCREENSHOT截屏
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.