lwxx

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格式,日历只要按这种格式就能显示信息

分类:

技术点:

相关文章:

  • 2021-11-27
  • 2022-01-01
  • 2022-01-01
  • 2021-08-06
  • 2021-08-06
  • 2021-11-20
  • 2021-08-05
猜你喜欢
  • 2021-10-08
  • 2021-08-06
  • 2022-01-30
  • 2021-11-09
  • 2021-12-22
  • 2021-10-02
相关资源
相似解决方案