Meteor server side : new date();

Hello everyone,

I can not understand how date management works in javascript server side

console.log(new Date(2020,6,1,0,0,0,0))

the result : 2020-06-30T13:00:00.000Z
Can someone explain this result to me ??
Where is the date, Where is the time, What does T mean? What does Z mean ?
Is there a site that explains all this?

Help would be valuable
Thank you

1 Like

The result is actually the ISO 8601 formatted time. The T separates the time from the date, and the Z means “Zulu” which means GMT or UTC (Coordinated Universal Time). The digits are YYYY-MM-DDThh:mm:ss.cccZ.

This is only the string representation of the new Date() object you created. The actual date object will have properties to extract the year, month, etc, and methods to change them. See the MDN Date() docs.

Most cloud servers are set to UTC so they are all running the same time. It is best practice to process and store all dates and times in databases as UTC, and only convert them into local time when they are displayed.


Considering the difference between what you entered and the resulting string, I’d say you’ve got a non-UTC timezone set on that computer and so it’s creating the date using the local time, and then giving you an ISO date using UTC as the string.

I usually get around this by only using ISO date strings

console.log(new Date("2020-07-01T00:00:00Z"))

You will see that it creates the date properly

1 Like

Thank you both. Very clear explanations, everything is working correctly.
Thanks for your help