Christian Fazzini Christian Fazzini - 4 months ago 12
Javascript Question

How to convert milliseconds into a readable date?

The following:

new Date(1324339200000).toUTCString()


Outputs:

"Tue, 20 Dec 2011 00:00:00 GMT"


I need it to return
Dec 20
. Is there a better method I can use besides
toUTCString()
? I am looking for any way to parse through milliseconds, to return a human readable date.

Answer

Using the library Datejs you can accomplish this quite elegantly, with its toString format specifiers: http://jsfiddle.net/TeRnM/1/.

var date = new Date(1324339200000);

date.toString("MMM dd"); // "Dec 20"
Comments