Reputation: 1025
With the following code:
var today = new Date();
console.log(String(today));
Chrome and FF return: "Tue Dec 27 2016 10:55:35 GMT+0700 (SE Asia Standard Time)"
BUT, Safari returns: "Tue Dec 27 2016 10:55:35 GMT+0700 (ICT)"
I want Safari return the same result like Chrome and FF did. How can I do it?
Is this a bug of Safari?
Upvotes: 5
Views: 7871
Reputation: 1956
It seems that Safari has some timezone issues not only with the standard acronyms (SE Asia Standard Time vs. ITC), but also detecting in which timezone the user is. Here are some issues I found:
Why is Safari confused about Date.getDay() for DST start in Sydney, Aus time zone?
Besides this, you can just add some code like the following
var today = new Date();
var x = String(today);
var ending;
for (var i = 0; i < x.length; i++) {
if (x[i] == "(") {
ending = i;
}
}
x = x.slice(0, ending);
x += "(SE Asia Standard Time)";
console.log(x);
I think this will allow you at least to format it properly.
Upvotes: 0
Reputation: 147363
I want Safari return the same result like Chrome and FF did. How can I do it?
You will need to reimplement the Date.prototype.toString method. The built–in method is implementation dependent, so as long as it fits the fairly loose requirement of ECMA-262 (see below), it's conformant.
There are various libraries that do a reasonable job of detecting the host timezone offset and converting it to a time zone name, generally the IANA timezone name. Converting to other time zone names such as "SE Asia Standard Time" is more problematic as likely not everyone in that timezone calls it the same name or uses the same abbreviation.
Is this a bug of Safari?
No. The specification simply requires that Date.prototype.toString returns "an implementation-dependent String value that represents [the date] as a date and time in the current time zone using a convenient, human-readable form.", so anything that fits that is fine.
What is the difference between "SE Asia Standard Time" and "Indochina Time"? There is no standard for time zone names, nor for their abbreviations, so anything that is "convenient, human-readable" for someone is sufficient.
Upvotes: 1