Does anyone know if there is a javascript ONLY way to convert an epoch number into a human readable date? I have this code, but I keep getting back a number. I want to convert this number into a human readable date if possible (ex: 2012/3/23).
This was a resource I used for my code... http://www.epochconverter.com/programming/
Play with my jsfiddle ... http://jsfiddle.net/4FSEp/
var myDate=new Date();
myDate = myDate.setFullYear(2012,3,23);
document.write(myDate);
document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());
Change
myDate = myDate.setFullYear(2012, 3, 23);
to
myDate.setFullYear(2012, 2, 23);
( edit — wow I didn't know setFullYear()
could also take a month and a day-of-month :-)
Those routines modify the date object, so there's no need to re-assign.
edit — if you have a date, and you want to move it to five days ahead of that date, you'd do this:
myDate.setDate( myDate.getDate() + 5 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.