jquery 解析数据库中的json日期为正常的格式
//在action从后台数据库中请求获得日期以后,得到的是json格式的数据,因此要解析才能显示在前台
1.在jsp页面写的代码如下:
<html>
<script>
Date.prototype.format = function(format) {
var o = {
"M+": this.getMonth() + 1, // month
"d+": this.getDate(), // day
"h+": this.getHours(), // hour
"m+": this.getMinutes(), // minute
"s+": this.getSeconds(), // second
"q+": Math.floor((this.getMonth() + 3) / 3), // quarter
"S": this.getMilliseconds()
// millisecond
}
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;
}
</script> <body>
<script>
var date = new Date();
console.info(date);
console.info(date.format("yyyy-MM-dd hh:mm"));
</script>
</body> </html>
2. 上述示例代码中,我们还是需要指定format,这里先抽象出一个formatDatebox函数,用于显示日期.
在js中写的代码如下:
function formatDatebox(value) {
if (value == null || value == '') {
return '';
}
var dt;
if (value instanceof Date) {
dt = value;
} else {
dt = new Date(value);
}
return dt.format("yyyy-MM-dd"); //扩展的Date的format方法(上述插件实现)
}
测试方法:
console.info(formatDatebox());//括号中的内容可以等价替换为数据库中请求得到的日期json数据
jquery 解析数据库中的json日期为正常的格式的更多相关文章
- Asp MVC 中处理JSON 日期类型
注:时间有点忙,直接copy 过来的,要查看原址: http://www.developer.com/net/dealing-with-json-dates-in-asp.net-mvc.html I ...
- 获取PostgreSQL数据库中得JSON值
在PostgreSQL数据库中有一列为JSON,要获取JSON中得数据可以用下面sql: select orderno as OrderNo ,amount as Amount ,ordertime ...
- 数据库中查询json 样式的值的sql语句
参考:http://www.lnmp.cn/mysql-57-new-features-json.html 方式一: 可以查到json中的Key:value SELECT * FROM EDI.edi ...
- js解析网络中的json数据
<?php echo <<<_END <html> <head> </head> <body> <div id=" ...
- mysql数据库中如何查询日期在两个时间之间的关系
select * from banner where addDate between '2017-06-04' and '2017-06-06';
- 在go中使用json作为主要的配置格式
最近在用go重构,在先前的代码中,我们使用的ini文件进行配置,但是因为很多历史遗留问题,导致配置混乱,维护困难,自然也需要考虑重构了. 通用配置格式 通用的配置格式有很多,常用的就有ini,json ...
- Java转换Json日期/Date(1487053489965+0800)/格式以及js时间格式 Tue Feb 14 2017 14:06:32 GMT+0800
/Date(1487053489965+0800)/用Java怎么转换成yyyy-MM-dd的格式 Tue Feb 14 2017 14:06:32 GMT+0800用Java怎么转换成yyyy-MM ...
- C#中Newtonsoft.Json 序列化和反序列化 时间格式
步骤 引用 using Newtonsoft.Json; using Newtonsoft.Json.Converters; 格式配置 IsoDateTimeConverter timeFormat ...
- PHP json的插入和解析在数据库中的操作
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. PHP中往数据库中存储json数据在项目开发中也经常遇到,下面我就 ...
随机推荐
- android 获取时间
首先,先说下java下可以正常使用的方法: import java.text.DateFormat; import java.text.SimpleDateFormat; import java.ut ...
- 1110Nested Loop Join算法
转自 http://blog.csdn.net/tonyxf121/article/details/7796657 join的实现原理 join的实现是采用Nested Loop Join算法,就是通 ...
- mvc4 ajax.beginform表单验证
@{ Layout = null; } @model MvcApplication1.Models.User @using (Ajax.BeginForm("create", &q ...
- Andriod ADB开启Activity、Service以及BroadCast(包括参数的传递)
/*****************开启Activity 并传递参数*******************/ 使用am命令启动Activity并传递参数的方法,也能用作C层与Java进行数据传递的一 ...
- struts2的核心和工作原理
struts2的核心和工作原理 设计目标 Struts设计的第一目标就是使MVC模式应用于web程序设计.技术优势 Struts2有两方面的技术优势,一是所有的Struts2应用程序都是基于clien ...
- 网络流最小割 POJ 3469
题意 2个CPU n个任务 给出在第一个 第二个运行时的花费 m 个 a b 不在同一个CPU运行的额外花费 建图 源点 -> n -> 汇点 权 a1 ...
- windows2003开启vpn服务
远程连接登陆到Windows服务器,在配置VPN之前,需要设置两个地方: 1.请确认windows自带的防火墙处于关闭状态,可以在我的电脑点右键>>管理>>服务和应用程序> ...
- MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令
介绍背水一战 Windows 10 之 MVVM(Model-View-ViewModel) 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 ...
- the comment lines of the blast tabular format
进行Blast比对,用参数-m 6 可以以列表的方式输出结果,结果中从左到右每一列的意义分别是: [00] Query id [01] Subject id [02] % identity [03] ...
- vmware安装ubuntu卡在install vm-tools
vmware,安装ubuntu或者centos,都有这个问题:vmware自作聪明,提示说"快速安装",然后会使用一个autoinst.iso文件来快速安装,并且装完系统后该重启了 ...