How to get current time with jQuery

后端 未结 15 855
青春惊慌失措
青春惊慌失措 2020-12-07 08:10

The following returns time in microseconds, for example 4565212462.

alert( $.now() );

How do I convert it to a human readable time format,

15条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 08:44

    Convert a Date object to an string, using one of Date.prototype's conversion getters, for example:

    var d = new Date();
    d+'';                  // "Sun Dec 08 2013 18:55:38 GMT+0100"
    d.toDateString();      // "Sun Dec 08 2013"
    d.toISOString();       // "2013-12-08T17:55:38.130Z"
    d.toLocaleDateString() // "8/12/2013" on my system
    d.toLocaleString()     // "8/12/2013 18.55.38" on my system
    d.toUTCString()        // "Sun, 08 Dec 2013 17:55:38 GMT"
    

    Or, if you want it more customized, see the list of Date.prototype's getter methods.

提交回复
热议问题