JS Date.Format
// 对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;
}
JS Date.Format的更多相关文章
- js Date format(日期格式化:yyyy-MM-dd HH:mm:ss.S)
今天在做日期显示的时候,那个显示格式困扰了很久,各种组件都尝试了,总是不如意,最后自己网上找了一个,然后稍微修改一下,感觉这个Util挺常用的,这里mark一下 Date.prototype.form ...
- javascript Date format(js日期格式化) (转)
方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) ...
- [转]javascript Date format(js日期格式化)
方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) ...
- javascript Date format(js日期格式化)
这个用这比较爽,记录一下// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年( ...
- [荐]javascript Date format(js日期格式化)
cnblog:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html 方法一: // 对Date的扩展,将 Date ...
- js new Date().Format
/** * * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符 * 年(y)可以用 1-4 ...
- javascript Date format(js日期格式化) 转载
本文转载地址http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html // 对Date的扩展,将 Date 转化为指定格 ...
- js Date.parse() format.
date format android chrome linux chrome Mobile safari ios chrome windows safari linux firefox window ...
- coding++ :javascript Date format (js日期格式化)
方式一: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1 ...
随机推荐
- android:style.xml
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2006 The Andr ...
- Android定位&地图&导航——基于百度地图移动获取位置和自动定位
一.问题描述 使用百度地图实现如图所示应用,首先自动定位当前我起始位置(小圆点位置),并跟随移动不断自动定位我的当前位置 百度Api不同版本使用会有些差异,本例中加入lib如下: 二.编写MyAppl ...
- fastreport totalpage 只有设置doublepassreport为true 才正确否则为0
fastreport totalpage 只有设置doublepassreport为true 才正确否则为0
- C# Like参数化 小记
strBuilder.Append(" and b.name like '%' + @name + '%'"); parameters.Add(new SqlParameter(& ...
- Jenkins 安装或更新插件失败
试试这个插件网址是否可以在网页中打开 http://mirror.xmission.com/jenkins/updates/current/update-center.json 如可以,把这个网址 ...
- sruts2:单个文件上传,多个文件上传(属性驱动)
文件上传功能在Struts2中得到了很好的封装,主要使用fileUpload上传组件. 1. 单个文件上传 1.1 创建上传单个文件的JSP页面.显示提交结果的JSP页面 uploadTest1.js ...
- golang append
1) Append a slice b to an existing slice a: a = append(a, b...) 2) Copy a slice a to a new slice b: ...
- 怎样在EPLAN P8里创建自己想要的电气元件符号
1.打开Eplan P8 ,新建一个名为"新项目"的项目,然后选择菜单"工具"----"主数据"-----"符号库"-- ...
- 如何在终端实时展现git分支
在微博上看到ghosTM55在终端可以实时展现出当前运行的分支,觉得很奇特,于是google了一把.这里面存在两个内容,第一个bash,第二个是git bash基础: 了解到linux的shell存在 ...
- TP-Link路由器刷dd-wrt的linux,无线信号增强不少
家里面TP-LINK WR841ND v3老路由器各方面都不错,双天线,300M,用了好几年了,但摆在客厅里面,最远的卧室处无线就不是很稳定了,想了各种增强解决办法: 1.更换天线. 一 ...