Determine minutes until midnight

前端 未结 4 730
不思量自难忘°
不思量自难忘° 2020-12-19 01:58

How would you go about determining how many minutes until midnight of the current day using javascript?

4条回答
  •  忘掉有多难
    2020-12-19 02:37

    function minutesUntilMidnight() {
        var midnight = new Date();
        midnight.setHours( 24 );
        midnight.setMinutes( 0 );
        midnight.setSeconds( 0 );
        midnight.setMilliseconds( 0 );
        return ( midnight.getTime() - new Date().getTime() ) / 1000 / 60;
    }
    

提交回复
热议问题