zoukankan      html  css  js  c++  java
  • JAVA日期JSON格式转换

    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 toDate(objDate,format){
    
      var date = new Date();
    
      date.setTime(objDate.time);
    
      date.setHours(objDate.hours);
    
      date.setMinutes(objDate.minutes);
    
      date.setSeconds(objDate.seconds);
    
      return date.format(format);
    
      }
    var newLine = "<br />";
    
    var re = /(w+)@(w+).(w+)/g
    var src = "Please send mail to george@contoso.com and someone@example.com. Thanks!"
    
    var result;
    var s = "";
    
    // Get the first match.
    result = re.exec(src);
    
    while (result != null) {
        // Show the entire match.
        s += newLine;
    
        // Show the match and submatches from the RegExp global object.
        s += "RegExp.lastMatch: " + RegExp.lastMatch + newLine;
        s += "RegExp.$1: " + RegExp.$1 + newLine;
        s += "RegExp.$2: " + RegExp.$2 + newLine;
        s += "RegExp.$3: " + RegExp.$3 + newLine;
    
        // Show the match and submatches from the array that is returned
        // by the exec method.
        for (var index = 0; index < result.length; index++) {
            s +=  index + ": ";
            s += result[index];
            s += newLine;
        }
    
        // Get the next match.
        result = re.exec(src);
    }
    document.write(s);
    
    // Output:
    //  RegExp.lastMatch: george@contoso.com
    //  RegExp.$1: george
    //  RegExp.$2: contoso
    //  RegExp.$3: com
    //  0: george@contoso.com
    //  1: george
    //  2: contoso
    //  3: com
    
    //  RegExp.lastMatch: someone@example.com
    //  RegExp.$1: someone
    //  RegExp.$2: example
    //  RegExp.$3: com
    //  0: someone@example.com
    //  1: someone
    //  2: example
    //  3: com
  • 相关阅读:
    在wampserver环境下配置多个版本的PHP支持
    Jetbrains全系列完美破解--------亲测可用
    python学习笔记1:元组
    python学习笔记0:列表
    入坑:分享几个优秀的编程博客
    java集合-EnumMap与EnumSet
    java集合-TreeSet
    java集合-TreeMap
    java集合-HashMap(JDK1.8)
    java集合-HashSet
  • 原文地址:https://www.cnblogs.com/wh-king/p/3147524.html
Copyright © 2011-2022 走看看