Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 936 Bytes

File metadata and controls

38 lines (25 loc) · 936 Bytes

Dates

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date.

We can construct new date objects by passing in the specified year, month, day, hour, minute, second, etc.:

var d = new Date(2025,4,2)
d //> Fri May 02 2025 00:00:00 GMT-0400 (Eastern Daylight Time)
var dt = new Date(2025,4,2, 11, 30)
dt //> Fri May 02 2025 11:30:00 GMT-0400 (Eastern Daylight Time)

By default if we omit passing any parameters we will get the current date and time:

var now = new Date()
now

Date Formatting

The date object has various formatting methods that will help us display it in different ways. Here are just a few date formatting examples:

var d = new Date(2025,4,2)

d //> Fri May 02 2025 00:00:00 GMT-0400 (Eastern Daylight Time)

d.toDateString() //> Fri May 02 2025

d.toLocaleDateString() //> 5/2/2025

d.toISOString().slice(0, 10) //> 2025-05-02