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.
If you need milliseconds, you need to add a further multiplication / division by 1000. For example, converting from epoch time (milliseconds) to a date would be "=((((A1/1000)/60)/60)/24)+DATE(1970,1,1)".
To convert a second measurement to a millisecond measurement, multiply the time by the conversion ratio. The time in milliseconds is equal to the seconds multiplied by 1,000.
A millisecond (from milli- and second; symbol: ms) is a unit of time in the International System of Units (SI) equal to one thousandth (0.001 or 10−3 or 1/1000) of a second and to 1000 microseconds.
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"
You can use datejs and convert in different formate. I have tested some formate and working fine.
var d = new Date(1469433907836); // Parameter should be long value
d.toLocaleString() // 7/25/2016, 1:35:07 PM
d.toLocaleDateString() // 7/25/2016
d.toDateString() // Mon Jul 25 2016
d.toTimeString() // 13:35:07 GMT+0530 (India Standard Time)
d.toLocaleTimeString() // 1:35:07 PM
d.toISOString(); // 2016-07-25T08:05:07.836Z
d.toJSON(); // 2016-07-25T08:05:07.836Z
d.toString(); // Mon Jul 25 2016 13:35:07 GMT+0530 (India Standard Time)
d.toUTCString(); // Mon, 25 Jul 2016 08:05:07 GMT
No, you'll need to do it manually.
function prettyDate(date) {
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
return months[date.getUTCMonth()] + ' ' + date.getUTCDate() + ', ' + date.getUTCFullYear();
}
console.log(prettyDate(new Date(1324339200000)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With