One can omit the year
in options
and get the day-month format correctly but a date string is obviously no good without a year
value:
var options = {
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
//year: "numeric",
month: "short",
day: "2-digit",
hour12: false,
timeZoneName: "short",
weekday:"short"
}
Returns:
Fri, Sep 27 1:38:30 PM ET
Fri 27 Sep 18:38:30 United Kingdom Time
So here is a temporary workaround until we find out what is going on with this; You can set the weekday
separately for en-GB
to get the desired outcome, but you end up with long weekday names:
var options = {
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
year: "numeric",
month: "short",
day: "2-digit",
timeZoneName: "short",
weekday: "short"
}
var date = new Date("Fri Sep 27 2013 13:38:30 GMT-0400");
options.timeZone = "America/New_York";
console.log(date.toLocaleDateString("en-US",options));
options.timeZone = "Europe/London";
options.weekday = "long";
console.log(date.toLocaleDateString("en-GB",options));
This returns:
Fri, Sep 27, 2013 1:38:30 PM ET
Friday, 27 Sep 2013 18:38:30 United Kingdom Time
I'm still trying to find the cause of this. This doesn't seem to be an ICU issue which returns expected values for both locales (see the result for en-GB
and en-US
). It might be that asking for a format with short weekday names and year
causes the format matcher to fall back to en
(which uses E, MMM d y
). Finding out whether this is a defect or not, needs more looking into. I will update here if I find out.
One small note about explicitly setting the hour12
. Considering that the default value of this is locale-dependent, I believe it's better to leave that out, too (it's overridden anyway as you see in the output time format for en-GB
).