• jsp 判断当前时间是否符合设置的时间条件


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">
    #abc {
    300px;
    }
    
    </style>
    
    
    <title>Insert title here</title>
    <script type="text/javascript">
    function getCurrentDate(){
    //1. 创建Date对象
    var date = new Date(); //没有填入任何参数那么就是当前时间
    //2. 获得当前年份
    var year = date.getFullYear();
    //3. 获得当前月份 js中月份是从0到11. 
    var month = date.getMonth()+1; 
    //4. 获得当前日
    var day = date.getDate();
    //5. 获得当前小时
    var hour = date.getHours();
    //6. 获得当前分钟
    var min = date.getMinutes();
    //7. 获得当前秒
    var sec = date.getSeconds();
    //8. 获得当前星期
    var week = date.getDay(); //没有getWeek
    // 2014年06月18日 15:40、:30 星期三
    var time=year+"年"+changeNum(month)+"月"+day+"日 "+hour+":"+min+":"+sec+" "+parseWeek(week);
    alert(time);
    var curr=hour*60*60+min*60+sec;
    alert(curr);
    var startime=17*60*60+30*60
    var endtime=21*60*60
    if(curr<startime){
    alert("还没有开始");
    }else if(curr>endtime){
    alert("已经结束");
    }else if(curr>=startime&&curr<=endtime){
    alert("活动进行中");
    
    }
    }
    
    //解决 自动补齐成两位数字的方法
    function changeNum(num){
    if(num < 10){
    return "0"+num;
    }else{
    return num;
    }
    
    }
    //将数字 0~6 转换成 星期日到星期六
    function parseWeek(week){
    var arr = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    //    0 1 2 3 .............
    return arr[week];
    }
    
    </script>
    </head>
    <body>
    <input type="text" id="abc" />    <input type="button" onclick="getCurrentDate()" value="点我开始" />
    </body>
    </html>

    注意:以上获取的当前时间为本地时间,人为更改本地时间可以绕过此逻辑!

  • 相关阅读:
    Python pandas 入门 05 JSON
    Python matplotlib 画图入门 07 散点图
    Python matplotlib 画图入门 06 绘制多图
    Python pandas 入门 04 CSV 文件
    Python pandas 入门 01 安装
    Python 入门示例系列 35 迭代器与生成器
    Python matplotlib 画图入门 03 绘图线
    Python pandas 入门 目录
    Python 零散知识点琐碎知识
    Python numpy 入门系列 目录
  • 原文地址:https://www.cnblogs.com/appium/p/10008600.html
Copyright © 2020-2023  润新知