Three Wolves Howling at the JSON Date Moon

JSON date formatting can seem like such a daunting proposition that even a Three Wolf Moon T-Shirt under your JC Penneys Oxford won’t summon the answer.  This issue ground me into the dirt but good, so I wanted to share the solution with you. 

There are clues to be gleaned. Bertrand Le Roy wrote an excellent post on JSON dates helpful in understanding the issues at hand. This Stack Overflow answer supporting Bertrand Le Roy’s guidance is probably a ready solution, but I couldn’t make it happen. Perhaps you can.

Not finding the secret sauce after several latenight geek hours on a Saturday night, I considered Dave Ward’s point that the client date is essentially an object with presentation value only, so why not pass a string from the Service?  Thus to display the date in the Sueetie Recent Member Activity feature I could have assigned a ToLongDateString() date to an unused string field in the WCF Service, then use that field for the JQuery output.

But I stayed on it, wanting to use a JSON date on the client side like a real man.  With no further ado, here’s how I handled the formatting of a JSON date to display just the way I wanted it.  First I grabbed Steven Levithan’s DateFormat .JS which was referenced on the Stack Overflow thread I mentioned earlier. I added a script reference to ~/scripts/date.format.js in my AJAX Script Manager and used dateFormat() on a Date() cast of the JSON date property.

I’ll never get those hours back, but hopefully you’ll do something of value with them, like howl at the moon and experience the power of the Three Wolves T-Shirt!

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.