Is there a better way of getting the next "whole" Date by second? #2544
Unanswered
lloydjatkinson
asked this question in
Q&A
Replies: 1 comment
-
Hmm yeah it would be nice to have a more generalized rounding method. Making a note of this. I'm assuming you also want the milliseconds to be set to 0 right? Using import { setSeconds, addMinutes, startOfMinute } from "date-fns";
const now = new Date();
const result1 = setSeconds(addMinutes(now, 1), 0);
const result2 = startOfMinute(addMinutes(now, 1));
console.log(result1.toISOString()); // 2021-07-02T18:36:00.932Z
console.log(result2.toISOString()); // 2021-07-02T18:36:00.000Z I would also consider simply going pure JS with this one. const now = new Date();
now.setMinutes(now.getMinutes() + 1, 0, 0);
console.log(now.toISOString()); // 2021-07-02T18:36:00.000Z |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to get the next minute (as in, current date + 1 minute) but without the seconds.
This is what I've come up with. Is there a better solution?
roundToNearestMinutes
isn't suitable for this because it can round down to the current date/time.Beta Was this translation helpful? Give feedback.
All reactions