| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/Date | [Back] [Original] |
Get to know MDN better
const date1 = new Date("December 17, 1995 03:24:00");
// Sun Dec 17 1995 03:24:00 GMT...
const date2 = new Date("1995-12-17T03:24:00");
// Sun Dec 17 1995 03:24:00 GMT...
console.log(date1 === date2);
// Expected output: false
console.log(date1 - date2);
// Expected output: 0
new Date()
new Date(value)
new Date(dateString)
new Date(dateObject)
new Date(year, monthIndex)
new Date(year, monthIndex, day)
new Date(year, monthIndex, day, hours)
new Date(year, monthIndex, day, hours, minutes)
new Date(year, monthIndex, day, hours, minutes, seconds)
new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds)
Date()
Date() new
Date()
Date
dateString Date.parse() ECMA262 ISO 8601 IETF RFC 2822
Date Date.parse ISO 8601 YYYY-MM-DDTHH:mm:ss.ssZ RFC 2822
"1970-01-01" UTC "1970-01-01T12:00"
dateObject Date Date new Date(dateObject.valueOf()) valueOf()
Date() Date day 1 0 UTC
11 monthIndex 59 minuteshours new Date(1990, 12, 1) 1991 1 1 new Date(2020, 5, 19, 25, 65) 2020 6 20 2:05
new Date(2020, 5, 0) 2020 5 31
yearmonthIndex 0 11
day 1
hours 0 23 0
minutes 0
seconds 0
milliseconds 0
new Date()Date() Date UNIX -8,640,000,000,000 8,640,000,000,000 Date toString() Invalid Date
Date() new new Date().toString() Date() new
JavaScript
const today = new Date();
const birthday = new Date("December 17, 1995 03:24:00"); //
const birthday = new Date("1995-12-17T03:24:00"); // ISO-8601
const birthday = new Date(1995, 11, 17); // 0
const birthday = new Date(1995, 11, 17, 3, 24, 0);
const birthday = new Date(628021800000); //
Date() Date new Date(undefined) new Date()
console.log(new Date(undefined)); // Invalid Date
undefined NaNnull 0
console.log(new Date(null)); // 1970-01-01T00:00:00.000Z
Array.prototype.toString() ISO 8601 Date()
console.log(new Date(["2020-06-19", "17:13"]));
// Chrome 2020-06-19T17:13:00.000Z "2020-06-19,17:13"
// Firefox "Invalid Date"
| ECMAScript 2027 LanguageSpecification # sec-date-constructor |
DateDate.prototype.getDate()Date.prototype.getDay()Date.prototype.getFullYear()Date.prototype.getHours()Date.prototype.getMilliseconds()Date.prototype.getMinutes()Date.prototype.getMonth()Date.prototype.getSeconds()Date.prototype.getTime()Date.prototype.getTimezoneOffset()Date.prototype.getUTCDate()Date.prototype.getUTCDay()Date.prototype.getUTCFullYear()Date.prototype.getUTCHours()getUTCMilliseconds()Date.prototype.getUTCMinutes()Date.prototype.getUTCMonth()Date.prototype.getUTCSeconds()Date.prototype.getYear()Date.prototype.setDate()Date.prototype.setFullYear()Date.prototype.setHours()Date.prototype.setMilliseconds()Date.prototype.setMinutes()Date.prototype.setMonth()Date.prototype.setSeconds()Date.prototype.setTime()setUTCDate()Date.prototype.setUTCFullYear()Date.prototype.setUTCHours()Date.prototype.setUTCMilliseconds()Date.prototype.setUTCMinutes()Date.prototype.setUTCMonth()Date.prototype.setUTCSeconds()Date.prototype.setYear()Date.prototype.toDateString()Date.prototype.toISOString()Date.prototype.toJSON()Date.prototype.toLocaleDateString()Date.prototype.toLocaleString()Date.prototype.toLocaleTimeString()Date.prototype.toString()Date.prototype.toTemporalInstant()Date.prototype.toTimeString()Date.prototype.toUTCString()Date.prototype.valueOf()Date.prototype[Symbol.toPrimitive]Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()| Web Proxy Viewer | New URL | Original Page |