<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>时间事件</title>
</head>
<body>

</body>
<script>

  var int_time=new Date();//使用Date获取网络时间;
  function title(){
  var sys_time= int_time.getHours();//这里只需要整点时间,所以我提取的是"时";

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

  console.log(typeof sys_time)//可以输出变量名看出来,这个变量是Number类型;

    if(sys_time>0&&sys_time<=6){
    alert("再睡会就天亮了");
    }  if(sys_time>6&&sys_time<12){
      alert('坚持一下,要吃午饭了');
    }if(sys_time>=12&&sys_time<18){
      alert('午饭已经吃过了,晚饭还远吗?');
    }if(sys_time>=18&&sys_time<=23){
      alert('忙了一天,放松一下,可以做一下爱做的事了');
    }
  }
title()

</script>
</html>

 

//做这种时间事件的方法很多,本次就分享这一个,希望对你会有帮助.

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄