MomentJS返回错误的Unix时间戳

时间:2018-09-23 10:19:50

标签: javascript time momentjs unix-timestamp

此刻,我有时间(对象):

 console.log(getSmtpDetails())

现在是 2018年9月22日

当我在对象上调用const data = [ { //here you have your smtp details id: 1 }, { //here you have your smtp details id: 2 }, { //here you have your smtp details id: 3 }, { //here you have your smtp details id: 4 } ] function getSmtpDetails(){ return data[Math.floor(Math.random() * data.length)]; } console.log(getSmtpDetails()) 时,我得到Moment {_isAMomentObject: true, _isUTC: false, _pf: {…}, _locale: Locale, _d: Sat Sep 22 2018 00:00:00 GMT+0200 (Středoevropský letní čas), …} 的时间是2018年9月21日。为什么?哪里有问题?

1 个答案:

答案 0 :(得分:0)

我认为这是时区问题。片刻正在考虑时区并可能更改日期。

时间戳1537567200表示:

  • 在您所在的时区:2018年9月22日星期六03:30:00 AM
  • UTC:2018年9月21日,星期五,晚上10:00:00

尝试以下方法,它应该可以正常工作。

moment.utc().format();
相关问题