Moment.js包含日期格式中间的文本 [英] Moment.js Include text in middle of date format
问题描述
我的格式为2015年1月27日上午8:17,我需要使用moment.js显示。我正在使用格式
I have a format of "Jan. 27, 2015 at 8:17 AM" that I need to display using moment.js. I'm using the format
moment.format('MMM. D, YYYY at h:mm A z');
一切都很有效,除了at这个词。如何将该单词显示为单词而不是at中的a被翻译为am / pm。现在使用该日期格式,它最终看起来像这样:2015年1月27日上午8:17。注意amt而不是at。
Everything works great except for the word "at". How can I get that word to display as a word instead of the "a" in "at" being translated to the "am/pm". Right now using that date format it ends up looking like this: Jan. 27, 2015 amt 8:17 AM. Notice the "amt" instead of "at".
有没有简单的方法让它不处理a作为格式的一部分?我已经尝试拆分输出并在第三个空格后手动输入at但是我想要一个更干净的代码。
Is there any simple way of getting it to not process the "a" as part of the format? I have already tried splitting the output and manually entering the "at" after the third space but I'd like a cleaner code if possible.
推荐答案
使用方括号逃脱它
moment().format('MMM. D, YYYY [at] h:mm A z');
// produces: "Jan. 30, 2015 at 2:46 PM "
这篇关于Moment.js包含日期格式中间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!