Search code examples
javascripttitaniumepoch

convert milliseconds and to local time and date javascript


I developing an android application using titanium in that i need to convert the Milliseconds time to UTC local time format.For that i tried several js but didn't worked out.

Perfect link that converts milliseconds to local time

My millisecond time format will be 1396250512

I need to convert to local time like Monday, March 31, 2014 12:51:51 PM

new Date(+new Date * 1000).toLocaleString()

i used this to convert ms to local time..But Each time i trying the above code gives me different time.


Solution

  • I don't know about the Titanium. But using javascript here is the way.

    var time = new Date().getTime(); // Get milliseconds
    var date = new Date(time);// Milliseconds to date
    alert(date.toString());
    
    
    var time = 1396250512;
    var date = new Date(time);// Milliseconds to date
    alert(date.toString());
    

    Get time only

    var time = 1396250512;
    var date = new Date(time);// Milliseconds to date
    var t=date.toString().split(" ");
    alert(t[4]);