Using momentjs to convert date to epoch then back to date

前端 未结 2 1450
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 15:12

I\'m trying to convert a date string to epoch, then epoch back to the date string to verify that I\'m providing the correct date string.

var epoch = moment(\         


        
2条回答
  •  清歌不尽
    2020-12-04 15:38

    http://momentjs.com/docs/#/displaying/unix-timestamp/

    You get the number of unix seconds, not milliseconds!

    You you need to multiply it with 1000 or using valueOf() and don't forget to use a formatter, since you are using a non ISO 8601 format. And if you forget to pass the formatter, the date will be parsed in the UTC timezone or as an invalid date.

    moment("10/15/2014 9:00", "MM/DD/YYYY HH:mm").valueOf()
    

提交回复
热议问题