// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
// 调用: var time1 = new Date().Format("yyyy-MM-dd");var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");

  

最新文章

  1. [Sass]混合宏
  2. Maven详解之聚合与继承
  3. struts2 拦截器 interceptor
  4. JAVA 继承 extends
  5. 屏幕分辨率与FPS
  6. 函数mem_area_alloc
  7. 深入研究Block用weakSelf、strongSelf、@weakify、@strongify解决循环引用(上)
  8. IOPS=(Queue Depth)/(IO latency)
  9. poj 3262 Protecting the Flowers 贪心
  10. java中a++与++a区别
  11. Chapter 2 Open Book——17
  12. TForm类
  13. windows 系统验证是否为正版
  14. shiro的rememberMe不生效
  15. 从零开始学 Web 之 JS 高级(三)apply与call,bind,闭包和沙箱
  16. mysql复习之一
  17. SqlServer执行大的数据库脚本出错解决方法
  18. MonoBehaviour类Invoke, Coroutine
  19. c++日志输出库 spdlog 简介(3)多线程控制台输出日志
  20. Android之开源项目汇总

热门文章

  1. 第十二章 设计用户界面 之 设计自适应的UI布局
  2. cvCanny的参数
  3. 基于Myeclipse的三大框架(SSH)整合
  4. 悦读FM客户端应用源码
  5. spring 中bean学习笔记
  6. Python 学习日志9月20日
  7. CSS3制作的一款按钮特效
  8. 转过来的Xpath语法
  9. sql mybatis 使用concat乱码
  10. Python-DB接口规范