Date.prototype.Format---对Date的扩展
// 对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 now = new Date();
var nowStr = now.format("yyyy-MM-dd hh:mm:ss");
//使用方法2:
var testDate = new Date();
var testStr = testDate.format("YYYY年MM月dd日hh小时mm分ss秒");
alert(testStr);
//示例:
alert(new Date().format("yyyy年MM月dd日"));
alert(new Date().format("MM/dd/yyyy"));
alert(new Date().format("yyyyMMdd"));
alert(new Date().format("yyyy-MM-dd hh:mm:ss"));
Date.prototype.Format---对Date的扩展的更多相关文章
- Date.prototype.format
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- Date.prototype.format,js下的时间格式处理函数
该方法在date的原型中扩展了format方法,使其可以方便的格式化日期格式输出. Date.prototype.format =function(format) { var o = { , //mo ...
- 扩展Date的format方法--格式化日期时间
Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, "d+& ...
- js 的date的format时间,获取当前时间,前一天的日期
Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + ...
- Date Json格式转换Date格式
CreateTime=\/Date(1458722493663+0800)\/ var CreateTime="/Date(1458722493663+0800)/";var st ...
- 使用Jaxb2进行xml与bean的转义时Date的format设置
参考http://jackyrong.iteye.com/blog/1826699 JAXB转换JAVA OBJECT到XML的时候,对java.util.Date的转换有些要注意的地方 输出的格式为 ...
- js扩展String.prototype.format字符串拼接的功能
1.题外话,有关概念理解:String.prototype 属性表示 String原型对象.所有 String 的实例都继承自 String.prototype. 任何String.prototype ...
- JavaScriptr -- 常用对象 String, date, prototype
<script type="text/javascript"> //给已有的对象添加自定义功能 function getMax() { var max = this[0 ...
- js中String.prototype.format類似于.net中的string.formitz效果
String.prototype.format = function(args) { if (arguments.length>0) { var result = this; if (argum ...
随机推荐
- Error: Duplicate key name 'PCS_STATS_IDX' (state=42000,code=1061)
以下异常说明mysql已经启动. 应先关掉先前启动的mysql.再执行初始化schema操作. $service mysql stop; # $HIVE_HOME/bin/schematool -db ...
- Chapter13
package scala /** * Created by EX-CHENZECHAO001 on 2018-04-04. */class Chapter13 { // 13 集合 // 所有的集合 ...
- about 字节
关于由于赋值导致字节的截断.字节扩展及数据类型的提升: 一.字节截断:int----->char 当一个字节(8位)放不下时,出现截断,直接取(最后一个字节)最后面面8位. 例如:1000000 ...
- git merge的参数--squash的用处
本地分支处理问题的过程中一般都是commit在本地分支,当验证完毕后就需要merge到baseline上. 在不懂merge的--squash这个参数前,我一般是这么操作的: 1.在本地分支" ...
- postgresql安装,java简单使用postgresql
一 整合 由于本人的学过的技术太多太乱了,于是决定一个一个的整合到一个springboot项目里面. 附上自己的github项目地址 https://github.com/247292980/spri ...
- Aspose.cell生成表格
public void ExportQueryPrj(HttpContext context) { //接受前端传递参数和数据 st ...
- c# string.format 的简写 $
var name = "huchao"; var info = $"你是谁,我叫:{name}"; Console.Write(info); Console.R ...
- Arduino连接SHT10温湿度传感器--返回值不正常解决办法
如题目,arduino中连接温湿度传感器,用的是一个github开源项目,地址:点击打开,其实这个就是一个封装好的库,下载后把解压的文件夹复制到Arduino目录下的librarys文件夹内,重启Ar ...
- Java爬虫初体验
年关将近,工作上该完成的都差不多了,上午闲着就接触学习了一下爬虫,抽空还把正则表达式复习了,Java的Regex和JS上还是有区别的,JS上的"\w"Java得写成"\\ ...
- 基于screen.width的伪响应式开发
一.站在用户的角度看问题 一个用户,访问一个web页面的真实场景是怎样的呢? 下面是某用户访问某站点的一个场景: 1. 小明打开了自己的电脑,访问了鑫空间-鑫生活: 2. 小明体内洪荒之力无法控制,疯 ...