为什么moment.js在格式化的日期时间增加了3分钟?

时间:2018-03-28 07:23:26

标签: momentjs

当我用moment.js格式化日期时间时,我得到了一个奇怪的行为。它增加了3分钟到日期时间。

如果没有特定格式,则08:00

moment("2018-03-25T06:00:00Z").format()
"2018-03-25T08:00:00+02:00"

但如果我格式化日期时间,我得到了08:03

moment("2018-03-25T06:00:00Z").format("YYYY/MM/DD HH:MM")
"2018/03/25 08:03"

为什么?



const withoutFormat = moment("2018-03-25T06:00:00Z").format();
const withFormat = moment("2018-03-25T06:00:00Z").format("YYYY/MM/DD HH:MM");

console.log(withoutFormat);
console.log(withFormat);

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.js"></script>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

这只是因为MM给出了月号。如果您希望12小时使用h/hh,则需要24小时H/HH和分钟m/mm。这是doc

const withoutFormat = moment("2018-03-25T06:00:00Z").format();
const withFormat = moment("2018-03-25T06:00:00Z").format("YYYY/MM/DD hh:mm");

console.log(withoutFormat);
console.log(withFormat);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.js"></script>

答案 1 :(得分:1)

Name更改为Sub RenameIt(Cpy As String, CName As String) Do Wscript.Sleep 100 Loop Until Dir(Worksheets("Workpad").[b1] & "NEW INVOICES\FOR EMAILING\To Email.pdf") <> "" Do Wscript.Sleep 100 Name Worksheets("Workpad").[b1] & _ "NEW INVOICES\FOR EMAILING\To Email.pdf" _ As Worksheets("Workpad").[b1] & _ "NEW INVOICES\FOR EMAILING\" & CName & Cpy & ".pdf" Loop Until Err.Number = 0 End Sub ,因为HH:MM用于{j}中的HH:mm

&#13;
&#13;
MM
&#13;
months
&#13;
&#13;
&#13;