Gunjan Patel
Gunjan Patel

Reputation: 2372

convert Millisecond to Date and Date to Millisecond

I want to convert date to millisecond as per follow I converted.

var d = new Date(1454911465467) \\ output : Mon Feb 08 2016 11:34:25 GMT+0530 (IST)

Now I want to convert using output to millisecond.

var d = new Date('Mon Feb 08 2016 11:34:25 GMT+0530 (IST)').getTime() \\output : 1454911465000

Expected output : 1454911465467

Is their any way to convert these type of millisecond?

Upvotes: 0

Views: 624

Answers (1)

Alexander Elgin
Alexander Elgin

Reputation: 6956

Milliseconds are not specified in 'Mon Feb 08 2016 11:34:25 GMT+0530 (IST)'. The date precision here is down to seconds. Hence 467 milliseconds are missed in the second result.

You can check e.g.

var originalDate = new Date(1454911465467);
var clonnedDate = new Date(originalDate.getFullYear(), originalDate.getMonth(), originalDate.getDate(), originalDate.getHours(), originalDate.getMinutes(), originalDate.getSeconds(), originalDate.getMilliseconds());
document.write(clonnedDate.getTime());

Upvotes: 2

Related Questions