Is there any easy solution for translating a unix timestamp like this:
1350664800
Into a human readable date like:
10/19/2012 11:40 AM
?
I’m working on alerting the jQuery UI datepicker (with datetimepicker addon) so that it selects and displays the ‘human’ date, sends the unix date to the server, then translates it back to the ‘human date’ on open. I have the translation going with this function:
function unixTranslate() {
$('input[name=valueTextField]').each(function () {
var unixTimestamp = ($(this).datetimepicker("getDate").getTime() / 1000) + 3600;
$(this).attr('title', unixTimestamp);
});
}
Which outputs the correct number from the datetimepicker widget, but I’m not sure how to translate it back.
Edit
Okay, so I have it converting back to a JS date object with this:
var myDate = new Date(unixTimestamp * 1000);
alert(myDate);
However, now I’m having an issue parsing it to make it look like how I want. Can anyone help?
Something (a bit messy) like this should get the job done: