1

I am currently trying to convert a few dates in Javascript however these dates are defined with milliseconds and that data cannot be lost when converted. I have tried doing the following

var dateString = '2009-07-15 11:00:00.675';
dateString = dateString.split(' ').join('T');
var date = new Date(dateString);
date = date.getTime() / 1000;

But date returns

date= 1247655600.675

I have read a few topics in stack overflow but the only "solution" I saw was the following:

parseInt((new Date('2012.08.10').getTime() / 1000).toFixed(0))

But this does not consider milliseconds either. What should I do to correctly convert a date to unix timestamp with milliseconds precision?

Thank you.

2
  • 1
    A Date's time value is milliseconds, dividing by 1,000 gives seconds. So just don't divide by 1000. Commented Feb 6, 2017 at 20:33
  • 1247655600.675 has a precision of milliseconds, but the units are seconds. Commented Feb 7, 2017 at 3:19

1 Answer 1

2

try this, no need to do /1000

var dateString = '2009-07-15 11:00:00.675';
dateString = dateString.split(' ').join('T');
var date = new Date(dateString);
date = date.getTime();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.