Reputation: 129
I am creating an app which asks the users for 2 dates, then it calculates the time between them dates.
But the dates have seconds in them so instead of 90 minutes I am getting 89 minutes.
So I can convert this:
startTime: Sat Apr 09 2022 09:00:39 GMT+0100 (Irish Standard Time)
Into this:
startTime: Sat Apr 09 2022 09:00:00 GMT+0100 (Irish Standard Time)
I would preferably do this with DayJS
Upvotes: -1
Views: 2665
Reputation: 3870
you can use the startOf method of day.js.
dayjs().startOf("minute") // will set to 0 the seconds and ms
dayjs().startOf("hour") // will set to 0 the minutes, seconds and ms
Upvotes: 0
Reputation: 529
let dateVal = dayjs(new Date());
dateVal = dateVal.set('seconds', 0).set('millisecond', 0);
https://day.js.org/docs/en/get-set/set
https://day.js.org/docs/en/get-set/get#list-of-all-available-units
Upvotes: 1
Reputation: 129
I came up with a solution with the help of James!
values.startTime = dayjs(time[0].setUTCSeconds(0)).toDate();
Thank you!
Upvotes: 1