MDGSF Software Engineer

[Web] javascript Date

2018-07-16
mdgsf
Web

var now = new Date();
console.log(now); // 2018-07-16T09:18:52.740Z
console.log("now.getFullYear() = ", now.getFullYear()); // 2018 年份。
console.log("now.getMonth() = ", now.getMonth()); // 0~11, 5 表示 6 月。
console.log("now.getDate() = ", now.getDate()); // 16 表示 16 号。
console.log("now.getDay() = ", now.getDay()); // 1 表示星期一,3 表示星期三。
console.log("now.getHours() = ", now.getHours()); // 17
console.log("now.getMinutes() = ", now.getMinutes()); // 18
console.log("now.getSeconds() = ", now.getSeconds()); // 52
console.log("now.getMilliseconds() = ", now.getMilliseconds()); // 740
console.log("now.getTime() = ", now.getTime()); // 1531732732740

console.log("-----------------------------------------------");

var d = Date.parse('2018-07-16T09:25:00.320Z');
console.log("d = ", d);

console.log("-----------------------------------------------");

var d = new Date(1435146562875)
console.log("d.toLocaleString() = ", d.toLocaleString()); // 2015-6-24 19:49:22
console.log("d.toUTCString() = ", d.toUTCString()); // Wed, 24 Jun 2015 11:49:22 GMT

console.log("-----------------------------------------------");

var d = new Date(2015, 5, 19, 20, 15, 30, 123);
console.log("d = ", d);

weixingongzhonghao

Comments

Content