The javascript Date.toLocaleDateString() is silly.
What I need is a function that allows me to simplify the date according to preference.
It would be nice if there were a function which would read the browser date formats (plural) and take an optional parameter telling it which format to use.
I’ll explain:
“MM/DD/YYYY” works great for the US and anyone willing to put up with them/us.
“DD/MM/YYYY” is the most common format for people interested in a short simple date format.
“Weekday, Month DayOfMonth, Year” is only useful if you want a super-long and language-dependent output.
I could use this:
var s = "/";
if(locale=='us')
var dateString = Date.getDate()+s+Date.getDay()+s+Date.getFullYear();
else
var dateString = Date.getDay()+s+Date.getDate()+s+Date.getFullYear();
But I’m looking for a more elegant solution that will allow me to store a date mask or format string so people can change the way their dates are displayed according to their own tastes. (Even the super-long language-dependent one if they like it enough.)
Should I re-prototype the Date.toString() method to interpret parameters? Is there a better way?
I ran into a very powerful library that takes care of dates and generic formatting:
http://blog.stevenlevithan.com/archives/date-time-format(Wrong link)
http://jawe.net/wiki/dev/jsdateformat/home
Is pretty powerful and configurable. (It supports java-style formats that I need, such as the “MEDIUM” date format)
Moment appears to be useful and feature-full (just no Medium format): https://github.com/timrwood/moment