Date.prototype.Format = function (formatStr) {
var str = formatStr;
var Week = ['日', '一', '二', '三', '四', '五', '六']; str = str.replace(/yyyy|YYYY/, this.getFullYear());
str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100)); str = str.replace(/MM/, this.getMonth() > 9 ? (this.getMonth() + 1).toString() : '0' + (this.getMonth() + 1));
str = str.replace(/M/g, this.getMonth()); str = str.replace(/w|W/g, Week[this.getDay()]); str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
str = str.replace(/d|D/g, this.getDate()); str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
str = str.replace(/h|H/g, this.getHours());
str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
str = str.replace(/m/g, this.getMinutes()); str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
str = str.replace(/s|S/g, this.getSeconds()); return str;
}

由于Date中getMonth()函数得到的月份是从0开始,所以需要再+1

参考:http://www.cnblogs.com/carekee/articles/1678041.html

js Date扩展Format()函数的更多相关文章

  1. js date扩展方法

    /* File Created: 四月 28, 2015 */ //日期加上天数得到新的日期 //dateTemp 需要参加计算的日期,days要添加的天数,返回新的日期,日期格式:YYYY-MM-D ...

  2. js Date.parse() format.

    date format android chrome linux chrome Mobile safari ios chrome windows safari linux firefox window ...

  3. Date.prototype.format,js下的时间格式处理函数

    该方法在date的原型中扩展了format方法,使其可以方便的格式化日期格式输出. Date.prototype.format =function(format) { var o = { , //mo ...

  4. Javascript扩展Date的prototype实现时间format函数 2017-06-29T09:10:00.000Z日期转换

    /*时间格式化 公用方法*/ Date.prototype.format = function(fmt) { // var o = { "M+": this.getMonth() ...

  5. js Date 时间格式化的扩展

    js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...

  6. 扩展JS Date对象时间格式化功能

    在自己JS代码中引入一下代码: Date.prototype.format =function(format) { var o = { "M+" : this.getMonth() ...

  7. 对js中的Date扩展,格式化日期

    /** * 对Date的扩展,将 Date 转化为指定格式的String 月(M).日(d).12小时(h).24小时(H).分(m).秒(s).周(E).季度(q) * 可以用 1-2 个占位符 年 ...

  8. JS Date.Format

    // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...

  9. js Date日期对象的扩展

    // 对Date的扩展,将 Date 转化为指定格式的String// 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位 ...

随机推荐

  1. (转)webservice 测试窗体只能用于来自本地计算机的请求

    Question: WebService部署成站点之后,如果在本地测试webservice可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或者"The test form is ...

  2. Action<T> 和 Func<T> 委托

    概述: 除了为每个参数和返回类型定义一个新委托类型之外,可以使用Action<T> 和 Func<T> 委托. Action<T> Action<T>委 ...

  3. 设置cas server使用http非安全协议

    目录 1.tomcat添加https安全协议 2.下载cas server端部署到tomcat上 3.CAS服务器深入配置(连接MYSQL) 4.Apache Shiro 集成Cas作为cas cli ...

  4. [转]Windows Shell 编程 第九章 【来源:http://blog.csdn.net/wangqiulin123456/article/details/7987969】

    第九章 图标与Windows任务条 如果问一个非程序人员Windows最好的特色是什么,得到的答案应该是系统最有吸引力的图标.无论是Windows98现在支持的通用串行总线(USB)还是WDM(看上去 ...

  5. CSS3 @font-face (webfont)

    先大概介绍下计算机领域常见的字体类型与格式. 点阵字体(Bitmap Font)点阵字体也叫位图字体,其中每个字形都以一组二维像素信息表示.这种文字显示方式于较早前的电脑系统(例如未有图形接口时的 D ...

  6. U盘装系统系列二—-如何设置U盘启动

    老毛桃U盘启动制作好之后,如何设置U盘启动呢?我的是华硕的电脑,开机后按F2进入BIOS设置(不同主板可能不一样,比如有的是按向下键或者Del键,可以在网上查下看看),按Tab键选中Boot:按向下键 ...

  7. Jasper_crosstab_group _Error incrementing crosstab dataset

    error detail: net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRRuntimeExceptio ...

  8. 价格更低、SLA 更强的全新 Azure SQL 数据库服务等级将于 9 月正式发布

    继上周公告之后,很高兴向大家宣布更多好消息,作为我们更广泛的数据平台的一部分, 我们将在 Azure 上提供丰富的在线数据服务.9 月,我们将针对 Azure SQL 数据库推出新的服务等级.Azur ...

  9. 【转】win7+ubuntu双系统安装方法--不错

    原文网址:http://blog.csdn.net/lvanneo/article/details/16885121 前段时间又安装一下win7+ubuntu双系统,过段时间就会忘记,这次自己写下来, ...

  10. delphi中通过http控件上载文件的问题(紧急) 整理的CSDN 帖子

    http控件能不能实现post文件?要求效果就像普通的html中通过表单(form中<INPUT TYPE="FILE" NAME="FILE1" SIZ ...