Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime.toSeconds returns seconds.milliseconds #565

Closed
ThorstenBux opened this issue Aug 31, 2019 · 2 comments

Comments

@ThorstenBux
Copy link

commented Aug 31, 2019

Hi,

I'm wondering why DateTime.toSeconds() does return a floating-point number xxxxx.yyy where yyy represents the milliseconds. If I wanted to have milliseconds I would have called .toMilliSeconds()

Expected:
DateTime.fromISO("2019-08-31T00:27:39.689Z").toSeconds() // --> 1567211259

Actual:
DateTime.fromISO("2019-08-31T00:27:39.689Z").toSeconds() // --> 1567211259.689

@icambron icambron closed this Aug 31, 2019

@icambron

This comment has been minimized.

Copy link
Member

commented Aug 31, 2019

The reason people typically want toSeconds is that they want to pass the result a UNIX system that expects datetimes expressed as epoch seconds, and I believe those systems generally allow for decimals in the input. Thus, leaving in the milliseconds makes the conversion to that representation lossless.

You can alway call Math.floor() or Math.round() on it.

@ThorstenBux

This comment has been minimized.

Copy link
Author

commented Sep 3, 2019

@icambron, thanks for clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.