Convert date to UTC using moment.js

后端 未结 11 846
囚心锁ツ
囚心锁ツ 2020-12-13 01:43

Probably and easy answer to this but I can\'t seem to find a way to get moment.js to return a UTC date time in milliseconds. Here is what I am doing:

var dat         


        
11条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 01:57

    This is found in the documentation. With a library like moment, I urge you to read the entirety of the documentation. It's really important.

    Assuming the input text is entered in terms of the users's local time:

     var expires = moment(date).valueOf();
    

    If the user is instructed actually enter a UTC date/time, then:

     var expires = moment.utc(date).valueOf();
    

提交回复
热议问题