Get ISO 8601 using Intl.DateTimeFormat

Years later I find that the accepted answer which is based on the ‘fo’ or ‘foo’ (Faroese) locale no longer works. Perhaps it is as Jukka speculated: the Faroese authorities decided to switch (to d/m/y) or their locale info got corrected.

And, unfortunately, the explicit ‘ISO8601’ locale that is proposed has still not been added so that is a long way off if it ever happens.

Regarding the comment by @felixbuenemann, I’m a little puzzled as Node 10 does not support locale data and just gives “en-us” results for all (perhaps it was a custom build of Node).

But I concur that the Canadian locales (‘fr-CA’ and ‘en-CA’) are good substitutes – the point is to use a locale such as Canada or Sweden where ISO 8601 has been adopted so the locale format is very unlikely to change. Sweden (sv-SE) is actually better than Canada because it doesn’t add a non-standard comma and uses more conformant timezone identifiers.

So, what I’m suggesting is

new Date().toLocaleString( 'sv-SE', o );
// where the options 'o' is defined as in the question or however you want 

which produces “2019-09-03 05:29:54”. Note that the space delimiter instead of ‘T’ is standard conformant too. Don’t append the ‘Z’ at the end (as in the question) unless you are overriding local time by setting the timeZone option to GMT.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)