0% found this document useful (0 votes)
14K views2 pages

Time Zones: Example

When working with dates in JavaScript, it is important to specify the time zone to avoid ambiguity. If no time zone is specified, dates will be converted to the time zone of the browser. It is safest to use the "MM/DD/YYYY" format for short dates to ensure consistency across browsers.

Uploaded by

Bogdan Chindris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14K views2 pages

Time Zones: Example

When working with dates in JavaScript, it is important to specify the time zone to avoid ambiguity. If no time zone is specified, dates will be converted to the time zone of the browser. It is safest to use the "MM/DD/YYYY" format for short dates to ensure consistency across browsers.

Uploaded by

Bogdan Chindris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Time Zones

When setting a date, without specifying the time zone, JavaScript will use the
browser's time zone.

When getting a date, without specifying the time zone, the result is converted
to the browser's time zone.

In other words: If a date/time is created in GMT (Greenwich Mean Time), the


date/time will be converted to CDT (Central US Daylight Time) if a user browses
from central US.

JavaScript Short Dates.


Short dates are written with an "MM/DD/YYYY" syntax like this:

Example
var d = new Date("03/25/2015");
Try it Yourself »

WARNINGS !
In some browsers, months or days with no leading zeroes may produce an
error:

var d = new Date("2015-3-25");

The behavior of "YYYY/MM/DD" is undefined.


Some browsers will try to guess the format. Some will return NaN.

var d = new Date("2015/03/25");

The behavior of "DD-MM-YYYY" is also undefined.


Some browsers will try to guess the format. Some will return NaN.

var d = new Date("25-03-2015");

You might also like