-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fromUnixTime ignored milliseconds #1917
Comments
@dd-han But even JavaScript Date will also give you the same result.
@leshakoss @kossnocorp shouldn't the function |
The Date constructor already supports timestamps in ms, so I think this request doesn't make much sense. const date = new Date(100)
console.log(date.toISOString()) // '1970-01-01T00:00:00.100Z'
console.log(date.getMilliseconds()) // 100, the ms component only of the date created
console.log(date.getTime()) // 100, ms since epoch
|
Oh hold on, let me re-open this. Do you mean that the Essentially, these two lines should match instead of truncating the decimal values? import { fromUnixTime } from "date-fns";
const ms = 1640888727872;
const sec = ms / 1000;
console.log(new Date(ms).toISOString()); // 2021-12-30T18:25:27.872Z
console.log(fromUnixTime(sec).toISOString()); // 2021-12-30T18:25:27.000Z There is a specific unit test for this, so it seems like it was intentional and behaving this way since it was introduced by #937. date-fns/src/fromUnixTime/test.ts Lines 17 to 20 in 871ea7a
I assume it would be treated as a breaking change, but maybe this could be considered for v3? @tan75 |
hi all, it is currently open for discussion. |
@tan75 some update? |
Hi
When I using date-fns convert Unix Timestamp to JavaScript Date Object. But milliseconds seem to be ignored, code:
https://github.com/date-fns/date-fns/blob/master/src/fromUnixTime/index.js#L29
The text was updated successfully, but these errors were encountered: