Extra-JS

  • here we put js stuff we may add later

Date instance

We use the Date() javascript object to represent time.

//To create a new Date() instance we 

let data= new Date( 2002, 02, 20, 10, 50, 22 )
//new Date(year,month,day,hours,minutes,seconds,ms)
Wed Mar 20 2002 10:50:22 GMT+0100 (Ora standard dell’Europa centrale)

//we can also use the ISO 8601 format as a STRING with specific syntax
let iso= new Date( "1995-12-17T03:24:00" ) YYYY-MM-DDTHH:mm:ss.sssZ
Sun Dec 17 1995 03:24:00 GMT+0100 (Ora standard dell’Europa centrale)

We can parse the Date value as a string:

//toString() is a string parsing like new Date()
let white= new Date()    //Sat Feb 04 2023 12:38:00 GMT+0100 / OBJECT
white.toString()         //Sat Feb 04 2023 12:38:00 GMT+0100 / STRING

The toLocateDateString() method returns a date string with a language-sensitive timezone:

//We can get different date strings based on the timeZones
white.toLocaleString()        //13/1/2023, 13:54:00
white.toLocaleString("en-US") //1/13/2023, 1:53:44 PM

//we can also get DATE and TIME 
white.toDateString()              //Fri Jan 13 2023
white.toLocaleDateString("en-US") //1/13/2023
white.toTimeString()              //14:19:43 GMT+0100 (Ora standard dell’Europa centrale)
white.toLocaleTimeString("en-US") //2:19:43 PM

//on Date the en-GB shows 13/01/2023
chevron-right.get() any timezone as a Date() Objecthashtag

We can use the return from .toLocateString() for a new Date() object but:

It's gonna be a Date() object, including all its methods .get()/.set()/etc

We use new Intl.DateTimeFormat().format() method to format a Date() according to the locale and formatting option:

Both toLocateString() and new Intl.DateTimeFormat().format() share similar options objects:

Only on .toLocateString() we can use "narrow" and "2-digit" values:

We can also .split(",") the data returned:

If you want to know more Timezones check herearrow-up-right, and languages herearrow-up-right.

We also have set() and get() methods for Date() objects:

We can get() a current date() information

Last updated