HTML CSS JavaScript SEO Python Posts Privacy About Contact

JS Dates

JavaScript Date objects let us work with dates.

By default, JavaScript will use the browser’s time zone and display a date as a full text string.

Creating Date Objects

Date objects are created with the new Date() constructor. There are 4 ways to create a new date object:

  • new Date()
  • new Date(year, month, day, hours, minutes, seconds, milliseconds)
  • new Date(milliseconds)
  • new Date(date string)
Preview

new Date(year, month, …)

new Date(year, month, ...) creates a new date object with a specified date and time. 7 numbers specify year, month, day, hour, minute, second, and millisecond (in that order).

Note: JavaScript counts months from 0 to 11. January is 0. December is 11.

Preview

Date Get Methods

You can easily extract the current year, month, or day using Date methods.

Preview