zoukankan      html  css  js  c++  java
  • ie 与 Chrome 时间格式化问题.

    ie 与 Chrome 时间格式化通用:

    new Date(res[i].Time.replaceAll("-", "/")).format("yyyy-MM-dd")

    replaceAll, format是扩展方法

    /*    
    所以可以用以下几种方式.:
    string.replace(new RegExp(strSearch, 'g'), strReplace);
    string:字符串表达式包含要替代的子字符串。
    strSearch:被搜索的子字符串。
    strReplace:用于替换的子字符串。
    */
    String.prototype.replaceAll = function(strSearch, strReplace, ignoreCase) {
        if (!RegExp.prototype.isPrototypeOf(strSearch)) {
            return this.replace(new RegExp(strSearch, (ignoreCase ? "gi" : "g")), strReplace);
        } else {
            return this.replace(strSearch, strReplace);
        }
    }

    /**
    * 将时间转换成固定格式输出
    * new Date().toFormat('yyyy-MM-dd HH:mm:ss');
    * new Date().toFormat('yyyy/MM/dd hh:mm:ss');
    * 只支持关键字(yyyy、MM、dd、HH、hh、mm、ss)HH:表示24小时,hh表示12小时
    */
    Date.prototype.format = function(format) {
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(), //day
            "h+": this.getHours(), //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
            "S": this.getMilliseconds() //millisecond
        }

        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }

        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    }

  • 相关阅读:
    python的lambda使用
    python的timedelta
    ptyhon读文件一行长度len为1022,出现\x00
    eclipse生成jar包
    linux 文件的软链接与硬链接(看着写的不错就转发了)
    各种VBA excel 命令、属性、方法
    键盘鼠标共享 Synergy
    关于 range 区域 excel
    php mssql几条常见的数据库分页 SQL 语句
    Get the Degree of Angle Between Hour and Minute Hand of a Clock at Anytime
  • 原文地址:https://www.cnblogs.com/chencidi/p/3781877.html
Copyright © 2011-2022 走看看