How to return the current timestamp with Moment.js?

前端 未结 11 1732
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 00:28

Folks,

I am trying to understand the MomentJS API. What is the appropriate way to get the current time on the machine?

var CurrentDate = moment();
<         


        
11条回答
  •  不知归路
    2020-12-23 00:52

    Here you are assigning an instance of momentjs to CurrentDate:

    var CurrentDate = moment();
    

    Here just a string, the result from default formatting of a momentjs instance:

    var CurrentDate = moment().format();
    

    And here the number of seconds since january of... well, unix timestamp:

    var CurrentDate = moment().unix();
    

    And here another string as ISO 8601 (What's the difference between ISO 8601 and RFC 3339 Date Formats?):

    var CurrentDate = moment().toISOString();
    

    And this can be done too:

    var a = moment();
    var b = moment(a.toISOString());
    
    console.log(a.isSame(b)); // true
    

提交回复
热议问题