I found this code in an old project I did, hope it helps. You might
have to mess with it little first.
function timeToHuman(x){
var theDate = new Date();
theDate.setTime(parseInt(x)); //this would remove the
millisecond part of it.
var dateString = theDate.toGMTString(); //guessing
you'll now have the date in string format here. To get individual
elements...
var arrDateStr = dateString.split(" ");
var month = getMonthNum(arrDateStr[2]);
var day = arrDateStr[1];
var year = arrDateStr[3];
var hour = arrDateStr[4].substr(0,2);
var minute = arrDateStr[4].substr(3,2);
var second = arrDateStr[4].substr(6,2);
if (x==0) return ("");
else return (day+ '/' + month + '/' + year + ' ' + hour +
':' + minute + ':' + second)
}
function getMonthNum(abbMonth){
var arrMon = new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec");
var i;
for(i=0; i<arrMon.length; i++)
{
if(abbMonth == arrMon[i])
return i+1;
}
return -1;
}
Lonifasiko wrote:
Hi,
I want to convert an UTC time to a Date object in Javascript.
The UTC time we have is a string that looks like "1160720058.377452373"
for example.
I've done it in Java but I'm not able to do it via Javascript, that
should be pretty similar...
I would really appreciate any help on this.
Thansk very much in advance.