JavaScript: Date Object

By Xah Lee. Date: . Last updated: .

Date is the value of the property key "Date" of the global object.

console.log ( window.hasOwnProperty ( "Date" ) ); // true

Date is a function object.

〔➤see JavaScript: Data Types

console.log ( typeof Date === "function" ); // true

The parent of Date is Function.prototype.

// parent of Date object
console.log ( Object.getPrototypeOf ( Date ) === Function.prototype ); // true

The purpose of Date is:

  1. To create a date instance. (by Date(…))
  2. Used as a namespace to hold static methods for working with date. For example, Date.parse(string).
  3. Holds the property key "prototype". The value of Date.prototype is the root parent object of all date instances. 〔➤see JavaScript: Prototype and Inheritance

Date Constructor

JavaScript: Date() Constructor

Properties


Date.prototype

JavaScript: Date.prototype

Date.now

Date.now ( )

Returns the milliseconds representation of current datetime. Sample return value: 1428601360919

Same as (new Date()).getTime().

var d1 = Date.now ();
var d2 = (new Date).getTime();
console.log ( d1 ); // 1481498123423
console.log ( d2 ); // 1481498123423

ECMAScript 2015 §Numbers and Dates#sec-date.now

Date.parse

Date.parse(date_time_string)

JavaScript Date.parse()

Date.UTC

Date.UTC ( year, month , date , hours , minutes , seconds , ms )

Returns the milliseconds representation of current datetime. Sample return value: 1428601360919

The parameters are exactly the same as new Date(), but interprets them as UTC. 〔➤see JavaScript: Date() Constructor

The year and month arguments are required.

If less than 2 arguments are given, result is implementation dependent.

var d = Date.UTC ( 2016, 12 , 17 );
console.log ( d ); // 1484611200000
console.log ( (new Date(d)).toString() ); // Mon Jan 16 2017 16:00:00 GMT-0800 (PST)

ECMAScript 2015 §Numbers and Dates#sec-date.utc

Reference

ECMAScript 2015 §Numbers and Dates#sec-date-objects

Date Topic

  1. JavaScript: Date Tutorial
  2. JavaScript: Date Object
  3. JavaScript: Date.prototype
  4. JavaScript Date.parse()
  5. JavaScript: Date() Constructor
  6. JavaScript: Compute Date Range

Object Reference

  1. JavaScript: Object Object
  2. JavaScript: Array Object
  3. JavaScript: Function Object
  4. JavaScript: String Object
  5. JavaScript: RegExp.prototype
  6. JavaScript: Date Object
  7. JavaScript: Set Object
  8. JavaScript: Map Object
  9. JavaScript: JSON Object
  10. JavaScript: Math Object
  11. JavaScript: Reflect Object
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.