JavaScript Dates – new Date and UTC

Leave a comment

In JavaScript, we can create a new date using:

var date1 = new Date("2018-01-01");

If we print this in the console, we actually get a different date:

This is because we are omitting the time, so UTC time is assumed. To display the “correct” date, add the time:

var date1 = new Date("2018-01-01 00:00");

This produces:




Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube


Leave a Reply

Your email address will not be published. Required fields are marked *