获取网络时间,在不同时间触发事件

<!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();//这里只需要整点时间,所以我提取的是"时";

  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>

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

昼以继夜,行走不息
原文地址:https://www.cnblogs.com/changx/p/10843764.html