Using the Best Date Format

When handling dates and time it seems that everyone thinks that everyone else is wrong. I would like adoption of user focused date format, that means, just go with whatever the user has chosen for their own local date format. Trying to get mass adoption of ISO 8601 is going to be a challenge I will never see beaten.

For example, there should be no more worrying that the dates 10/12/2015 - 11/13/2015 is somehow running into Smarch. That example was a bit contrived and one of the easier ones, but it will still force a few people to go back and re-read to then figure out how it should have been. Other examples can be not so clear: just what day is 2/1/2016? The only logical way to decode this is to make assumptions about the author (maybe requiring a bit of research) or get confirmation by other means.

It turns out I'm not alone, and this is a common problem. The developers of web browsers have thought of this too. Providing, in Javascript, the functions toLocaleString() and toLocaleDateString() for acting on dates to return a string the user will understand.

They are not hard to use ether. For example take this simple function that just puts a choice datetime into a span:

function setDateTime(id,when){

    e = document.getElementById(id);

    d = new Date(when);

    e.textContent = d.toLocaleString();

    e.title = d.toISOString();


And we can use it on a span:


The date is:

So even though I'm in a different timezone, and I like my date to look like 06 January 2015 ( I don't but that's the example), you should see the same time, correct for your timezone, and in your choice of format.


You may have spotted that we also set the title of the element, that sets the tooltip. You can now hover over the date to see the ISO8601 format!