简体   繁体   English

如何使用moment.js自定义日期格式的年份格式?

[英]How to customize year format in a date format using moment.js?

I need to get the following format using moment.js 我需要使用moment.js获取以下格式

Thu, 10 Oct 16, 2:00PM

The closest format I found using moment.js is using the following function. 我使用moment.js找到的最接近的格式正在使用以下函数。

moment(dateVar).format('llll')

where dataVar is the required date object.The output looks as follows 其中dataVar是必需的日期对象。输出如下所示

Thu, Oct 16, 2016 12:00 AM

I could not find any way to customise this date format or get the required result. 我找不到自定义此日期格式或获取所需结果的任何方法。

According to the moment docs you should be able to get your result by passing the following formatting string: 根据当前文档,您应该可以通过传递以下格式字符串来获得结果:

moment(dateVar).format('ddd, DD MMM YY, H:mmA');

I think this string should get you the desired result. 我认为该字符串应该可以为您带来预期的结果。 If I run it with the current date it returns this: 如果我使用当前日期运行它,则返回以下内容:

moment(new Date()).format('ddd, DD MMM YY, H:mmA');
//"Wed, 02 Nov 16, 10:25AM"

And extensive list of your display options with formatting strings is here: http://momentjs.com/docs/#/displaying/ 带有格式字符串的显示选项的广泛列表在这里: http : //momentjs.com/docs/#/displaying/

See http://momentjs.com/docs/#/displaying/ 参见http://momentjs.com/docs/#/displaying/

What you need is 您需要的是

ddd, D MMM YY, h:mmA

ddd - Day of week D -Day of month etc ddd-星期D-月份等

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

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