JSON存Date格式转换


JSON传递日期格式变形

  • 取出来的数据
  • 转变为JSON格式后
  • 传给前端
  • 经过这个方法后就能变为正常的时间
function transferTime(cTime){
	       var jsonDate = new Date(parseInt(cTime));
	       Date.prototype.format = function (format){
	             var  o = {
	                  "y+": this.getFullYear(),
	                  "M+": this.getMonth()+1,
	                  "d+": this.getDate(),
	                  "h+": this.getHours(),
	                  "m+": this.getMinutes(),
	                  "s+": this.getSeconds()
	             };
	             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] : ("" + o[k]).substr("" + o[k].length));
	                  }
	             }
	             return format;
	       };
	       var newDate = jsonDate.format("yyyy-MM-dd");
	       return newDate
	}
  • Ajax,for循环取出时间与事件类型,存入指定的JSON格式,日历只要按这种格式就能显示信息


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM