zoukankan      html  css  js  c++  java
  • 格式化时间,new Date()兼容IE

    ----------------------------------------------------------new Date()兼容IE
    var date = new Date(strDate.replace(/-/g, "/"));


    ---------------------------------------------------------格式化时间
    Date.prototype.format = function(format)
    {
    /*
    * format="yyyy-MM-dd hh:mm:ss";
    */
    var o = {
    "M+" : this.getMonth() + 1,
    "d+" : this.getDate(),
    "h+" : this.getHours(),
    "m+" : this.getMinutes(),
    "s+" : this.getSeconds(),
    "q+" : Math.floor((this.getMonth() + 3) / 3),
    "S" : this.getMilliseconds()
    }
    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;
    }

    //去掉空格
    function trim(str){
    str = str.replace(/^(s|u00A0)+/,'');
    for(var i=str.length-1; i>=0; i--){
    if(/S/.test(str.charAt(i))){
    str = str.substring(0, i+1);
    break;
    }
    }
    return str;
    }

  • 相关阅读:
    Cookies
    一个完整的upstart脚本分析
    squid总结
    python递归读取目录列表
    python删除文件
    ubuntu切割mp3文件
    TP-LINK TL-WN725N V2 / rtl8188eu Linux驱动安装
    ubuntu启动脚本
    su对环境变量做了什么
    sudoers文件配置
  • 原文地址:https://www.cnblogs.com/chai-blogs/p/7641511.html
Copyright © 2011-2022 走看看