moment.js时间不是UTC

时间:2017-07-21 18:29:50

标签: javascript momentjs

我尝试过moment.utc()和moment.format(' YYYY-MM-DD'),以便尝试在午夜获得当前年份,日期和时间。我遇到的问题是我正确地获得年,月和日,但是小时数是+4小时。

minimum = Date.parse(start.toISOString()).getTime();
maximum = Date.parse(end.toISOString()).getTime();

下面的代码段给出了开始日期和结束日期,但加上4小时

<?php
$amount = str_replace(",", "", '1,051.36') * 100; //105136
$number = (int)ceil($amount); //105136

1 个答案:

答案 0 :(得分:2)

如果要用moment()。utc()替换所有的moment()调用,它将按预期工作。见fiddle for more info

UTC<br/>
<div id="divUTC"></div><br/>
Your Local Time with respect to above UTC time<br/>
<div id="divLocal">
</div>    

$(function(){
    setInterval(function(){
        var divUtc = $('#divUTC');
        var divLocal = $('#divLocal');  
        //put UTC time into divUTC  
        divUtc.text(moment.utc().format('YYYY-MM-DD HH:mm:ss'));      

        //get text from divUTC and conver to local timezone  
        var localTime  = moment.utc(divUtc.text()).toDate();
        localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss');
        divLocal.text(localTime);        
      },1000);
    });