JS转换JSON格式时间
  fztgkkRjHIsV 2023年11月09日 47 0


JSON格式:

"drvierDate":{"date":9,"day":6,"hours":16,"minutes":30,"month":7,"nanos":0,"seconds":0,"time":1407573000000,"timezoneOffset":-480,"year":114}


toDate(drvierDate)
function toDate(obj){
	 var date = new Date();
	 date.setTime(obj.time);
	 date.setHours(obj.hours);
	 date.setMinutes(obj.minutes);
	 date.setSeconds(obj.seconds);
	 return date.format("yyyy-MM-dd hh:mm:ss"); //调用Date.prototype.format方法
Date.prototype.format
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;
}
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: XMemcached缓存系统 下一篇: js获取url参数值
  1. 分享:
最后一次编辑于 2023年11月09日 0

暂无评论

推荐阅读
  1BnnW8rtw7M9   2023年12月22日   140   0   0 i++Mathmathi++算法算法
fztgkkRjHIsV