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

Issue with format() when using milliseconds #895

Closed
joni7777 opened this issue May 3, 2020 · 4 comments
Closed

Issue with format() when using milliseconds #895

joni7777 opened this issue May 3, 2020 · 4 comments

Comments

@joni7777
Copy link

joni7777 commented May 3, 2020

Describe the bug
When you create a dayjs object, add 1 milliseconds to it and format to string, the string doesnt include the added milliseconds

const timestamp = dayjs();
console.log(timestamp.format('YYYY-MM-DDTHH:mm:ss.sss')) // ---> SAME
console.log(timestamp.add(1, 'millisecond').format('YYYY-MM-DDTHH:mm:ss.sss')) // ---> SAME
console.log(timestamp.add(0.001, 'second').format('YYYY-MM-DDTHH:mm:ss.sss')) // ---> SAME

Expected behavior
When you create a dayjs object, add 1 milliseconds to it and format to string, the string format should have the added milliseconds

const timestamp = dayjs();
console.log(timestamp.format('YYYY-MM-DDTHH:mm:ss.sss')) // ---> X
console.log(timestamp.add(1, 'millisecond').format('YYYY-MM-DDTHH:mm:ss.sss')) // ---> X + 1 milliseconds
console.log(timestamp.add(0.001, 'second').format('YYYY-MM-DDTHH:mm:ss.sss')) // ---> X + 1 milliseconds

Information

  • Day.js Version v1.8.26

Example
https://runkit.com/joni7777/dayjs-milliseconds-issue

@iamkun
Copy link
Owner

iamkun commented May 4, 2020

https://runkit.com/embed/1wlzrozab430
Screen Shot 2020-05-04 at 11 08 53 AM
seems ok?

@joni7777
Copy link
Author

joni7777 commented May 4, 2020

@iamkun Yea the valueOf() is working as expected, but the format() is not using the milliseconds

@joni7777
Copy link
Author

joni7777 commented May 4, 2020

It was may bad, i had a bad format for milliseconds, used 'YYYY-MM-DDTHH:mm:ss.sss' instead of 'YYYY-MM-DDTHH:mm:ss.SSS' (the .SSS in the end) 🤦‍♂️

@joni7777 joni7777 closed this as completed May 4, 2020
@aaronamm
Copy link

aaronamm commented Apr 8, 2024

As reference for others.
https://day.js.org/docs/en/display/format

Format Output Description
SSS 000-999 The millisecond, 3-digits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants