当前位置:网站首页>Moment. JS how to use epoch time to construct objects

Moment. JS how to use epoch time to construct objects

2022-06-24 01:28:00 HoneyMoose

If you are right about Epoch If you don't know very well , Please refer to the following post : UNIX Time : New era time (Epoch Time)

Moment.js You can use numbers directly to construct Moment Object's .

It should be noted that Epoch Time may have 2 A digital .

Compare the following 2 A digital :

1635795000000 1635795000

In fact, they all mean a time , The difference is that the first number takes milliseconds , The second number does not .

So in the construction Moment The methods used when creating objects are different .

To a number , We should use :

moment(1635795000000)  Just construct it directly .

For the second number , The method that should be used is ,moment.unix(1635795000)

From output , We can see that , If used .unix The way to do it , Will automatically add... After your input data 3 individual 0.

summary

Moment Objects are saved in milliseconds , Therefore, when constructing, if you use numbers to construct objects .

You need to consider the method to use , Otherwise, incorrect conditions may occur .

https://www.ossez.com/t/moment-js-epoch-time/13812

原网站

版权声明
本文为[HoneyMoose]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211118085336372F.html