admin管理员组文章数量:1417460
I am trying to format a date with moment.js using the ZH_CN locale. I am using the following code:
moment('2013-12-31T13:21:55+00:00').locale('zh_cn').format("LL h:m:s:SSS")
This returns the following date: 2013年12月31日 1:21:55:000
The time is not correctly formatted however. I was hoping the time would have the appropraite Chinese characters after each digit.I looked within moment-with-locales.js and noticed that the following is defined for the ZH_CN locale:
relativeTime : {
future : '%s内',
past : '%s前',
s : '几秒',
m : '1分',
mm : '%d分',
h : '1小时',
hh : '%d小时',
d : '1天',
dd : '%d天',
M : '1个月',
MM : '%d个月',
y : '1年',
yy : '%d年'
}
These characters are not getting returned in the time even though I specify them in the format string (h:m:s:sss). Anything I am doing wrong? Thanks!
I am trying to format a date with moment.js using the ZH_CN locale. I am using the following code:
moment('2013-12-31T13:21:55+00:00').locale('zh_cn').format("LL h:m:s:SSS")
This returns the following date: 2013年12月31日 1:21:55:000
The time is not correctly formatted however. I was hoping the time would have the appropraite Chinese characters after each digit.I looked within moment-with-locales.js and noticed that the following is defined for the ZH_CN locale:
relativeTime : {
future : '%s内',
past : '%s前',
s : '几秒',
m : '1分',
mm : '%d分',
h : '1小时',
hh : '%d小时',
d : '1天',
dd : '%d天',
M : '1个月',
MM : '%d个月',
y : '1年',
yy : '%d年'
}
These characters are not getting returned in the time even though I specify them in the format string (h:m:s:sss). Anything I am doing wrong? Thanks!
Share Improve this question asked Jan 11, 2016 at 17:02 illwalkwithyouillwalkwithyou 3591 gold badge6 silver badges21 bronze badges 01 Answer
Reset to default 3The relativeTime
customization only affects functions that produce relative time output, such as fromNow
.
Additionally, only the localized format specifiers such as LL
will contain the characters you're looking for. You can bine them to get the desired output.
var m = moment('2013-12-31T13:21:55+00:00').locale('zh_cn');
m.format("LL") // "2013年12月31日"
m.format("LLL") // "2013年12月31日凌晨5点21分"
m.format("LT") // "凌晨5点21分"
m.format("LTS") // "凌晨5点21分55秒"
m.format("LL[]LTS") // "2013年12月31日凌晨5点21分55秒"
I believe the last one will suit your needs. Note the use of []
is necessary just so that LL
and LTS
are interpreted as separate codes without introducing additional characters.
本文标签: javascriptMomentjs Format time for ZHCN localeStack Overflow
版权声明:本文标题:javascript - Moment.js Format time for ZH_CN locale - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745265770a2650589.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论