Momentjs seconds from now to a specific hour

I need to get the number of seconds from today to today with a specific hour.

moment().diff(moment().hour(23), 'seconds'); 

Accuracy is always in hours; I need it to be in seconds.

For example, if it’s 15:24 now. I get 28800.

+6
source share
1 answer

moment() is the current time, so if the current time is 15:24:32 moment().hour(23) returns 23:24:32. You need to set the minutes and seconds to 0 to get the difference between 15:24:32 and 23:00:00.

it

moment().diff(moment().hour(23).minute(0).second(0), 'seconds');

returns -27328 seconds when the current time is 15:24:32

+15
source

All Articles