简体   繁体   中英

How to show button only the time between 9am to 5pm in react js or javascript?

Let's say I have a button that should display only on the particular time period(9am to 5pm), otherwise the button should not display.

The if statement is only entered if the time is between 9:00 and 17:00 (5pm).

 const date = new Date(); const hours = date.getHours(); if (hours >= 9 && hours <= 16) { // add code to show button }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM