• 关于IE11版本下JS中时间判断的问题


    最近在做代码的优化及浏览器的兼容问题。遇到了谷歌、火狐、360兼容模式、IE(8以上)版本对时间判断大小的问题 。
    在谷歌、火狐、360、IE11以下IE8以上版本下
    var d1="2016-11-11 10:34:49";
    //当前时间
    // 获取当前时间hhmm的比较值
    function getOraNowTimeInt (){
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
    month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    + " " + date.getHours() + seperator2 + date.getMinutes()
    + seperator2 + date.getSeconds();

    return currentdate;
    

    }

    if(d<getOraNowTimeInt())
    {
    //永远走这的方法体了
    }
    而在IE11时,就出问题了,
    后续通过查资料得知,是IE将“yyyy-yy-mm”转换成了"yyyy/mm/dd"格式
    最终解决方法:
    function convertTimeToInt(time) {
    var result = null;
    if(time != null && time != ""){
    result = parseInt(time.replace(/-/g,"").replace(/:/g,""),10);
    }
    return result;
    }

    // 获取当前时间hhmm的比较值
    function getOraNowTimeInt (){
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
    month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    + " " + date.getHours() + seperator2 + date.getMinutes()
    + seperator2 + date.getSeconds();

    return convertTimeToInt(currentdate);
    

    }
    if(convertTimeToInt(d1)<convertTimeToInt())
    {
    //这样,就永远走这的方法体了
    }

  • 相关阅读:
    仿QQ信息弹出
    天高云淡 leobbs皮肤
    http://www.xywq.com/files/ganzhi11.htm
    用Silverlight打造位运算器(3)--完成
    用Silverlight打造位运算器(1)--制作简易工具条控件
    用Silverlight打造位运算器(2)--制作数字文本框控件
    Lucky Sequence[SRM403DIVI500]
    答复:“判断一个整数的二进制位中有多少个1”的提问
    Python 笔记(1)
    #define中的#、## && #@
  • 原文地址:https://www.cnblogs.com/ITyueguangyang/p/6114397.html
Copyright © 2020-2023  润新知