格式化日期(网上到处是),把下面的代码添加到jQuery.js文件中

//格式化日期
Date.prototype.format = function(format) {
/*
* eg:format="yyyy-MM-dd hh:mm:ss";
*/
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;
} //strDate.format("yyyy年MM月")

在页面上定义方法格式化json的日期

// val为经json直接序列化后的C#的DateTime类型的数据
function formatTime(val) {
var re = /-?\d+/;
var m = re.exec(val);
var d = new Date(parseInt(m[0]));
// 按【2012/02/13 09:09:09】的格式返回日期
return d.format("yyyy/MM/dd hh:mm:ss");
}

结果:

最新文章

  1. XIB——AutoLayout添加约束
  2. php对文本文件进行分页功能简单实现
  3. Angular js 之一些简单的js操作
  4. 【VerySky原创】怎样查找到CDHDR、CDPOS表中的OBJECTCLAS字段
  5. 怎么样用opencv将彩色图片转化成像素值只有0和255的灰度图?
  6. 【转】SocketRocket:iOS WebSocket客户端开源框架
  7. 【解题报告】[动态规划] RQNOJ - PID38 / 串的记数
  8. 关于json的知识整理
  9. 1010 [HNOI2008]玩具装箱toy
  10. gulp解决RequireJS
  11. spring mvc controller中获取request head内容
  12. Spring结合log4j(slf4j)
  13. mysql用户管理和pymysql模块
  14. NPM 报错--fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module
  15. MySql数据库学习笔记(1)
  16. PhotoSphereViewer 全景图
  17. RBAC 介绍 (权限)
  18. 20155317《网络对抗》Exp4 恶意代码分析
  19. “融而开放、合以创新”T-HIM融合通信技术开发实战
  20. HDU 4704 欧拉定理

热门文章

  1. How to install java and eclipse on linux
  2. SpringMVC自定义注入controller变量
  3. redis数据结构整理(一)
  4. EF架构~CodeFirst自关联表的插入
  5. Android Studio导入System Library步骤
  6. fir.im Weekly - 你与优秀源码之间只差一个 Star
  7. 更新日志 - BugHD 新增邮件告警功能
  8. Git使用相关
  9. 《C与指针》第八章练习
  10. 解析大型.NET ERP系统 企业信息化实施人员工具箱