Setting a greeting based on user's time (Good morning, good afternoon…)

后端 未结 6 1976
孤街浪徒
孤街浪徒 2021-02-02 11:13

Can anyone extrapolate on how to implement a basic \"good evening\" or \"good morning\" based on the user\'s time setting?

Perhaps PHP will fetch the server time, but I

6条回答
  •  长情又很酷
    2021-02-02 11:38

    const now = new Date().getHours();
    
    switch (true) {
        case (now<=12): console.log("Good Morning");break;
        case (now>12 && now<16): console.log("Good Afternnon");break;
        case (now>=16 && now<20): console.log("Good Evening");break;
        case (now>=20 && now<=24): console.log("Good Night");break;}
    

    This code is based on JavaScript, Hope this will help you.

提交回复
热议问题