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是要显示的格式

  • 相关阅读:
    Spring MVC+Spring +Hibernate配置事务,但是事务不起作用
    Spring MVC 上传文件
    早安日语1
    Spring MVC学习初篇
    Eclipse中查看JDK源码设置
    Eclipse常见设置及快捷键使用总结(更新中)
    Java中boolean型变量的默认值问题
    [转载]浅析Java中的final关键字
    Eclipse中Outline里各种图标的含义
    [转载]深入理解JAVA的接口和抽象类
  • 原文地址:https://www.cnblogs.com/htys/p/3869797.html
Copyright © 2011-2022 走看看