I want to use Intl.DateTimeFormat
to format a Date, and in the examples it says
// when requesting a language that may not be supported, such as
// Balinese, include a fallback language, in this case Indonesian
Great, so I want my fallback to be ISO 8601 in the case a language doesn't exist
// i.e. the same as/similar to
new Date().toISOString(); // "2014-07-31T02:42:06.702Z"
however
// Intl.DateTimeFormat([locales [, options]])
var o = {};
o.year = o.month = o.day = o.hour = o.minute = o.second = 'numeric';
new Intl.DateTimeFormat(['foo', 'iso8601'], o);
// RangeError: Invalid language tag: iso8601
This seems to be because iso8601
isn't part of
locales
A string with a BCP 47 language tag, or an array of such strings.
I've also tried using one I know works, e.g. en-GB
with a u-ca-iso8601
suffix but this doesn't produce any different result to without the suffix
var f = new Intl.DateTimeFormat(['foo', 'en-GB-u-ca-iso8601'], o);
f.format(new Date());
// 31/7/2014 03:35:26
Why isn't this working? Is there even a locale
which will give me the output I'm looking for?
I'd rather not have to write some complicated wrapper using e.g.
if (Intl.DateTimeFormat.supportedLocalesOf(['foo']).length === 0)