对于后台传过来的json数据是带T时间格式的坑处理的一些做法总结

new Date(data[j].addtime).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')

仅针对这个问题来说,不需要那么大量的代码即可完成

方案1(适用于中国标准时间):

var date = new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'')

方案2(只用于题目中所述的格式转换):

var date = new Date().toLocaleString().replace(/[年月]/g,'-').replace(/[日上下午]/g,'');

方案3(最准确但最麻烦,不推荐):

var date = new Date();  

var result = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();

转载 :http://blog.csdn.net/hj7jay/article/details/51433745

最新文章

  1. Mysql数据库登录问题:Your password has expired.
  2. 为什么内联函数,构造函数,静态成员函数不能为virtual函数
  3. IOS Suppot Font 苹果默认支持的字体一览(配图)
  4. ExtJs之Ext.util.Format
  5. 浩哥解析MyBatis源码(一)——执行流程
  6. 实例甜点 Unreal Engine 4迷你教程(4)之用C++实现添加子Widget到VerticalBox中以及ClearChildren
  7. mysql 索引B-Tree类型对索引使用的生效和失效情况详解
  8. 全局光照:光线追踪、路径追踪与GI技术进化编年史
  9. VS2017 WinFrom打包设置与教程
  10. [Swift]LeetCode78. 子集 | Subsets
  11. 关于信息系统设计与开发——案例:VIP系统
  12. python学习笔记(2)--基本语法元素
  13. nodeJS 调试debug
  14. 【原】The Linux Command Line - Processes
  15. vue 基础(一)
  16. shell脚本-实战防dos攻击
  17. cors跨域问题
  18. C#.NET常见问题(FAQ)-如何在不同窗体之间传递值
  19. MessagePack 学习笔记
  20. Linux Shell的 & 、&& 、 ||

热门文章

  1. Unescaped left brace in regex is illegal here in regex; marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/ at xxxx/usr/bin/automake line 3939.
  2. Python中的print、input函数以及Python中交换两个变量解析
  3. input标签(按钮)
  4. hdu--1029 编程之美 在数组a中 (元素个数n n是奇数)找一个数字 它出现的次数大于(n+1)/2
  5. CentOS下安装VirtualBox
  6. C++学习(二十九)(C语言部分)之 顺序表
  7. 【次小生成树】【Kruskal】【prim】【转】
  8. hdu 1556 A - Color the ball 其他做法
  9. EHCache学习
  10. 《DSP using MATLAB》Problem 6.20