zoukankan      html  css  js  c++  java
  • javascript

    alert(JSON.stringify(obj, null, 2));
    将对象转换为string

    alert(JSON.stringify(JSON.parse(str), null, 2));
    将字符串转换为json对象, 再转换为string


    毫秒时间格式化输出
    var date = new Date(timeval * 1000);
    return date.format("yyyy年MM月dd日 hh时mm分ss秒 星期W");
    Date.prototype.format = function(format) {
        var date = this;
        var o =
            {
                "M+" : date.getMonth()+1, //month
                "d+" : date.getDate(), //day
                "h+" : date.getHours(), //hour
                "m+" : date.getMinutes(), //minute
                "s+" : date.getSeconds(), //second
                "q+" : Math.floor((this.getMonth()+3)/3), //quarter
                "S" : date.getMilliseconds(), //millisecond
                "W": function () {
                    var week;
                    switch ( date.getDay()) {
                        case 0: week = "日"; break;
                        case 1: week = ""; break;
                        case 2: week = ""; break;
                        case 3: week = ""; break;
                        case 4: week = ""; break;
                        case 5: week = ""; break;
                        case 6: week = ""; break;
                    }
                    return week;
                }
            }
    
        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;
    };
  • 相关阅读:
    动态规划____类数字三角形
    动态规划____编辑距离
    123
    pair queue____多源图广搜
    JAVA练习01
    leetcode — binary-tree-maximum-path-sum
    leetcode — best-time-to-buy-and-sell-stock-iii
    leetcode — best-time-to-buy-and-sell-stock-ii
    leetcode — best-time-to-buy-and-sell-stock
    leetcode — triangle
  • 原文地址:https://www.cnblogs.com/listenerln/p/9056623.html
Copyright © 2011-2022 走看看