zoukankan      html  css  js  c++  java
  • json返回date类型转为字符串

    js代码如下:

    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;
        
    };
    //转化JSON日期格式
    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);

    }

    json返回调用:

    $.ajax({
                type:"POST",
                url:"/slark/member/orderinfo/orderInfoList.do",
                async:false,
                data:formParam,
                dataType:"json",
                success:function(data){
                        for(var i in data){
                            content = "<a href="">时间"+toDate(data[i].arrDate,"yyyy-MM-dd")+"</a>";
                            $("#contenter").append(content);
                        }
                    }
                });

    toDate(data[i].arrDate,"yyyy-MM-dd")

    yyyy-MM-dd是要显示的格式

  • 相关阅读:
    windbg条件断点总结
    使用openssl命令剖析RSA私钥文件格式
    RSA读取密钥——使用openssl编程
    OPENSSL中RSA私钥文件(PEM格式)解析【一】
    电商系统架构——系统鸟瞰图
    构建高并发高可用的电商平台架构实践
    一些PHP性能的优化
    CentOS的Gearman安装
    php安装gearman扩展实现异步分步式任务
    使用 Gearman 实现分布式处理
  • 原文地址:https://www.cnblogs.com/htys/p/3869797.html
Copyright © 2011-2022 走看看