js 处理Json 时间带T 时间格式
2024-10-10 01:09:11
对于后台传过来的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
最新文章
- Mysql数据库登录问题:Your password has expired.
- 为什么内联函数,构造函数,静态成员函数不能为virtual函数
- IOS Suppot Font 苹果默认支持的字体一览(配图)
- ExtJs之Ext.util.Format
- 浩哥解析MyBatis源码(一)——执行流程
- 实例甜点 Unreal Engine 4迷你教程(4)之用C++实现添加子Widget到VerticalBox中以及ClearChildren
- mysql 索引B-Tree类型对索引使用的生效和失效情况详解
- 全局光照:光线追踪、路径追踪与GI技术进化编年史
- VS2017 WinFrom打包设置与教程
- [Swift]LeetCode78. 子集 | Subsets
- 关于信息系统设计与开发——案例:VIP系统
- python学习笔记(2)--基本语法元素
- nodeJS 调试debug
- 【原】The Linux Command Line - Processes
- vue 基础(一)
- shell脚本-实战防dos攻击
- cors跨域问题
- C#.NET常见问题(FAQ)-如何在不同窗体之间传递值
- MessagePack 学习笔记
- Linux Shell的 &; 、&;&; 、 ||
热门文章
- Unescaped left brace in regex is illegal here in regex; marked by <;-- HERE in m/\${ <;-- HERE ([^ \t=:+{}]+)}/ at xxxx/usr/bin/automake line 3939.
- Python中的print、input函数以及Python中交换两个变量解析
- input标签(按钮)
- hdu--1029 编程之美 在数组a中 (元素个数n n是奇数)找一个数字 它出现的次数大于(n+1)/2
- CentOS下安装VirtualBox
- C++学习(二十九)(C语言部分)之 顺序表
- 【次小生成树】【Kruskal】【prim】【转】
- hdu 1556 A - Color the ball 其他做法
- EHCache学习
- 《DSP using MATLAB》Problem 6.20