javascript_Date object

//javascript_Date object

//------------------------------------------------Code 1:
var now = new Date();
console.log(now.getDate());
console.log(now.getDay());
console.log(now.getMilliseconds());
console.log(now.getTime());//Timestamp
//------------------------------------------------Code 1 explanation:
//1. Create a new date object
//2. The timestamp is an auto-incrementing integer, which represents the number of milliseconds from the moment when the GMT time zone starts at 0:00 on January 1, 1970 to the present.

//------------------------------------------------Code 2:
var d = new Date(2015, 5, 19, 20, 15, 30, 123);//Method 1
var d = Date.parse('2015-06-24T19:49:22.875+08:00');//Method 2: Parse a string in ISO 8601 format and return a timestamp
console.log(d);
//------------------------------------------------Code 2 explanation:
//1. Two ways to create a date object

//------------------------------------------------Code 3:
var d = new Date(1435146562875);
console.log(d.toLocaleString());
console.log(d.toUTCString());
//------------------------------------------------Code 3 explanation:
//1. Convert to local time zone and UTC time zone

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325048392&siteId=291194637