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

Feature request - function to quickly create ISO8601 stamp without milliseconds #651

Closed
cyberwombat opened this issue Jan 21, 2020 · 12 comments

Comments

@cyberwombat
Copy link

Unless I am missing something this is how one gets the DateTime without milliseconds:

DateTime.utc()
        .startOf('second')
        .toISO({ suppressMilliseconds: true }),

Which is rather verbose. So many systems use the ISO8601 format without milliseconds (ex: 2020-01-21T23:03:23Z) that it would be nice to have a faster way to crank these out? maybe a trimMilliseconds option or something.

And thanks for the lib - I've tried them all and love this one by far the most.

@icambron
Copy link
Member

I'd accept a PR for this

@cyberwombat
Copy link
Author

cyberwombat commented Jan 24, 2020

Cool. What do you think of creating a dedicated function toISODateTime()? else I think it would be an option like trimMilliseconds though that could create a bit of confusion between that and suppressMuliseconds

@icambron
Copy link
Member

I like the option better. If it's confusing, perhaps suppressMilliseconds needs a better name

@EzeGmnz
Copy link

EzeGmnz commented Apr 2, 2023

The following PR solves this by adding a new parameter #1412

@TheArKaID
Copy link

@EzeGmnz Is this not accepted, or am I missing a docs that mentions it?

@cyberwombat
Copy link
Author

@TheArKaID its in there. Perhaps not documented - is an option for toISO and toISOTime on DateTime as well as in Duration methods. See code: https://github.com/search?q=repo%3Amoment%2Fluxon+suppressMilliseconds&type=code

@TheArKaID
Copy link

@TheArKaID its in there. Perhaps not documented - is an option for toISO and toISOTime on DateTime as well as in Duration methods. See code: https://github.com/search?q=repo%3Amoment%2Fluxon+suppressMilliseconds&type=code

Thanks for mentioning it. But, it can only be suppressed if it is zero, isn't?
image

@cyberwombat
Copy link
Author

cyberwombat commented Jun 2, 2024 via email

@cyberwombat
Copy link
Author

@TheArKaID this is how I use it:

 DateTime.utc()
    .startOf('second')
    .toISO({ suppressMilliseconds: true })

@diesieben07
Copy link
Collaborator

Closing this, as ti has been implemented as shown above. It's also in the JSDoc for the relevant methods.

@TheArKaID Correct, Luxon will not hide information. If you want to output a timestamp without milliseconds, you have to have a timestamp without milliseconds.

@FabianoLothor
Copy link

It's weird, but this flag doesn't work for me without .set({ millisecond: 0 }), is it derided behavior?

@cyberwombat
Copy link
Author

@FabianoLothor been a while but sounds right as this comment does so. I used .startOf('second') which may do something similar. But been a while!

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

No branches or pull requests

6 participants