方法一:


原理是取中间的数,再转换成js的Date类型
function ChangeDateFormat(val) {
if (val != null) {
var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
//月份为0-11,所以+1,月份小于10时补个0
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate;
}
return "";
}

方法二:


var str = '/Date(1333245600000+0800)/';

function data_string(str) {
var d = eval('new ' + str.substr(1, str.length - 2));
var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
for (var i = 0; i < ar_date.length; i ++) ar_date[i] = dFormat(ar_date[i]);
return ar_date.join('-'); function dFormat(i) { return i < 10 ? "0" + i.toString() : i; }
}
alert(data_string(str));

-转载

json返回数据库的时间格式为/Date(1477294037000)/,怎样在前台进行格式化转换的更多相关文章

  1. 用js转换joson返回数据库的时间格式为/Date(*************)/

    原理是取中间的毫秒数,再转换成js的Date类型 function ChangeDateFormat(val) { if (val != null) { var date = new Date(par ...

  2. joson返回数据库的时间格式在前台用js转换

    function ChangeDateFormat(val) { if (val != null) { var date = new Date(parseInt(val.replace("/ ...

  3. Newtonsoft.Json 序列化和反序列化 时间格式

    From : http://www.cnblogs.com/litian/p/3870975.html 1.JSON序列化 string JsonStr= JsonConvert.SerializeO ...

  4. Angularjs中对时间格式:/Date(1448864369815)/ 的处理

    注:本文使用的 angular 版本为 1.3 版 我们在后台对数据进行json序列化时,如果数据中包含有日期,序列化后返回到前端的结果可能是这样的: /Date(1448864369815)/  . ...

  5. Newtonsoft.Json 序列化和反序列化 时间格式 [转]

    1.JSON序列化 string JsonStr= JsonConvert.SerializeObject(Entity); eg:   A a=new A(); a.Name="Elain ...

  6. [转]Newtonsoft.Json 序列化和反序列化 时间格式

    本文转自:http://www.cnblogs.com/litian/p/3870975.html 1.JSON序列化 string JsonStr= JsonConvert.SerializeObj ...

  7. 修改oracle数据库默认时间格式

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://ccchencheng.blog.51cto.com/2419062/929695 ...

  8. Newtonsoft.Json 序列化和反序列化 时间格式【转】

    1.JSON序列化 string JsonStr= JsonConvert.SerializeObject(Entity); eg:   A a=new A(); a.Name="Elain ...

  9. .Net Core---- 自带Json返回日期带T格式 解决

    前段时间再做core的列表显示中(前台代码是在.net core bootstrap集成框架上的(这是效果浏览地址:http://core.jucheap.com[效果地址来自:http://blog ...

随机推荐

  1. 【leetcode】Jump Game I & II (hard)

    Jump Game (middle) Given an array of non-negative integers, you are initially positioned at the firs ...

  2. 【leetcode】Minimum Size Subarray Sum(middle)

    Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...

  3. innodb之超时参数配置

    可参考:http://www.penglixun.com/tech/database/mysql_timeout.html 下面内容摘取自上面这个链接. connection_timeout,只是设置 ...

  4. IE8支持HTML5的占位符placeholder

    /*IE8支持placeholder占位符*/ if( !('placeholder' in document.createElement('input')) ){ $('input[placehol ...

  5. 测试Open Live writer

    这个东西究竟是怎么用的啊,看起来好高端的样子...

  6. poj 3661 Running

    题意:给你一个n,m,n表示有n分钟,每i分钟对应的是第i分钟能跑的距离,m代表最大疲劳度,每跑一分钟疲劳度+1,当疲劳度==m,必须休息,在任意时刻都可以选择休息,如果选择休息,那么必须休息到疲劳度 ...

  7. AngularJS 服务(Service)

    AngularJS 中你可以创建自己的服务,或使用内建服务. 什么是服务? 在 AngularJS 中,服务是一个函数或对象,可在你的 AngularJS 应用中使用. AngularJS 内建了30 ...

  8. sql server 的cpu使用率过高的分析

    有哪些SQL语句会导致CPU过高? 1.编译和重编译 编译是 Sql Server 为指令生成执行计划的过程.Sql Server 要分析指令要做的事情,分析它所要访问的表格结构,也就是生成执行计划的 ...

  9. samba 报错

    [root@GitLab data_nfs]# smbclient //localhost/public WARNING: The security=share option is deprecate ...

  10. 与你相遇好幸运,Sail.js定义其他主键

    uuid : { type: 'string', unique: true, required: true, primaryKey: true },