json时间格式化
//格式化日期字符串
String.prototype.jsonDateFormat = function (format) {
var date, timestamp, dtObj
timestamp = parseInt(this.toString().replace('/Date(', '').replace(')/', '').replace(/\+\d+/, ''), 10)// jsonDt.replace(/\/Date\((\d+)\)\//, "$1");
date = new Date(timestamp)// new Date(Number(timestamp));
dtObj = {
'M+': date.getMonth() + 1, // 月
'd+': date.getDate(), // 日
'h+': date.getHours(), // 时
'm+': date.getMinutes(), // 分
's+': date.getSeconds() // 秒
}
// 因为年份是4位数,所以单独拿出来处理
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
// 遍历dtObj
for (var k in dtObj) {
// dtObj的属性名作为正则进行匹配
if (new RegExp('(' + k + ')').test(format)) {
// 月,日,时,分,秒 小于10时前面补 0
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? dtObj[k] : ('00' + dtObj[k]).substr(('' + dtObj[k]).length))
}
}
return format
} 调用:
例如:CreateTime: "/Date(1571292406000)/"
CreateTime.jsonDateFormat('yyyy-MM-dd hh:mm:ss')
json时间格式化的更多相关文章
- Newtonsoft.Json 时间格式化
时间序列化经常多个T:“2017-01-23T00:00:00” 解决方案: 日期格式化输出,指定IsoDateTimeConverter的DateTimeFormat即可 IsoDateTimeCo ...
- json时间格式化问题
function jsonDateFormat(jsonDate) {//json日期格式转换为正常格式 try { var date = new Date(parseInt(jsonDate.rep ...
- C# DataTable转json 时间格式化
1.NewTonSoft.json public static string DataTableToJson(DataTable dt) { ) { return ""; } el ...
- JSON时间转换格式化
通常JSON时间一般是这样的格式. 1 /Date(1436595149269)/ 通常我们用AJAX获取下来的JSON数据,如果有时间,都是这种格式的.其中,中间的一段数字"1436595 ...
- [.Net Core 3.0+/.Net 5] System.Text.Json中时间格式化
简介 .Net Core 3.0开始全新推出了一个名为System.Text.Json的Json解析库,用于序列化和反序列化Json,此库的设计是为了取代Json.Net(Newtonsoft.Jso ...
- 表单序列化json字符串和js时间格式化
js时间格式化 new Date().format("时间格式") Date.prototype.format = function(fmt) { var o = { ...
- EasyUI Datagrid Datetime(EasyUI DataGrid 时间格式化)
EasyUI DataGrid 时间格式化 方法一: var Common = { //EasyUI用DataGrid用日期格式化 TimeFormatter: function (value, re ...
- JSon 事件格式化
JS~json日期格式化 起因 对于从C#返回的日期字段,当进行JSON序列化后,在前台JS里显示的并不是真正的日期,需要格式化时间 实现 function ChangeDateFormat(js ...
- Javascript 金额、时间格式化
一晃2017年已经过去了,2018年已经悄然而至.回首过去的2017年,工作还是一如既往,但生活却有了翻天覆地的变化.尚还觉得自己还小的自己,在过去的一年中却完成了两件人生大事,回想起来还是一脸懵逼, ...
随机推荐
- 3-6 merge操作
In [1]: import pandas as pd In [6]: left =pd.DataFrame({ 'A':['A0','A1','A2','A3'], 'B':['B0','B1',' ...
- 网络流之最大流Dinic --- poj 1459
题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...
- 如果使用jsp文件,需要在配置文件中配置resources项,才能让idea识别这个jsp文件
没有添加这一项在编译后的.class文件中的结构目录是这样子的 添加上这一个配置项,在class配置文件中的位置是这样子的: 添加的配置文件是这样子的: <resources> <r ...
- oracle左连接与右连接
left join(左联接) ---返回左表中的所有记录和右表中条件字段相等的记录. right join(右联接) ---返回右表中的所有记录和左表中联结字段相等的记录 inne ...
- 第一章 了解Web及网络基础
第一章 了解Web及网络基础 Web建立基础.HTTP如何诞生发展 1.使用HTTP协议访问Web 在浏览器地址栏中输入URL之后过程: 1)DNS 解析:浏览器查询 DNS,获取域名对应的 IP 地 ...
- eclipse中查找类、方法及变量被引用的地方
1.选中要查看的类.方法或变量,然后Ctrl+Shift+G或右键-->References--->Project,就可以找到它所有被引用的地方. 2.对于方法,还可以通过右键--> ...
- impala进阶
一.impala存储 1.文件类型 2.压缩方式 二.impala分区 1.创建分区方式 partitioned by 创建表时,添加该字段指定分区列表: create table t_person( ...
- BBS 03day
目录 BBS_03 day: 自定义标签 过滤器: 文章的点赞,点彩功能: 文章的评论功能 transaction用法: 自定义 标签代码展示: BBS_03 day: 自定义标签 过滤器: --&g ...
- [LeetCode] 902. Numbers At Most N Given Digit Set 最大为 N 的数字组合
We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}. (Not ...
- [LeetCode] 380. Insert Delete GetRandom O(1) 常数时间内插入删除和获得随机数
Design a data structure that supports all following operations in average O(1) time. insert(val): In ...