pthread
pthread

Reputation: 35

Different behaviors of java scripts toLocaleTimeString in Chrome and other browsers

Repro method: 1. Please change the p.c.’s time zone to “(UTC+2) E.Eurpe”, 2. Open IE and Chrome, in the JS console, type:

(new Date(2015,4,7,16,07,0)).toLocaleTimeString("en", {hour: "numeric", minute: "numeric", hour12: true});

Chrome return 3:07PM and IE return 4:07PM

Anyone knows why and how to fix it? Thanks. Other time-zone seems good.

Upvotes: 0

Views: 386

Answers (1)

securecodeninja
securecodeninja

Reputation: 2515

There's a huge possibility that your browser does not support the locales and options argument of the toLocaleTimeString() method.

As per documentation in MSDN and MDN:

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

https://msdn.microsoft.com/en-us/library/ie/474de325(v=vs.94).aspx

The locales and options parameters are not supported in all document modes and browser versions

Try to check for the locales and options support first using this code snippet

Upvotes: 0

Related Questions