js Date扩展Format()函数
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()函数的更多相关文章
- js date扩展方法
/* File Created: 四月 28, 2015 */ //日期加上天数得到新的日期 //dateTemp 需要参加计算的日期,days要添加的天数,返回新的日期,日期格式:YYYY-MM-D ...
- js Date.parse() format.
date format android chrome linux chrome Mobile safari ios chrome windows safari linux firefox window ...
- Date.prototype.format,js下的时间格式处理函数
该方法在date的原型中扩展了format方法,使其可以方便的格式化日期格式输出. Date.prototype.format =function(format) { var o = { , //mo ...
- Javascript扩展Date的prototype实现时间format函数 2017-06-29T09:10:00.000Z日期转换
/*时间格式化 公用方法*/ Date.prototype.format = function(fmt) { // var o = { "M+": this.getMonth() ...
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
- 扩展JS Date对象时间格式化功能
在自己JS代码中引入一下代码: Date.prototype.format =function(format) { var o = { "M+" : this.getMonth() ...
- 对js中的Date扩展,格式化日期
/** * 对Date的扩展,将 Date 转化为指定格式的String 月(M).日(d).12小时(h).24小时(H).分(m).秒(s).周(E).季度(q) * 可以用 1-2 个占位符 年 ...
- JS Date.Format
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- js Date日期对象的扩展
// 对Date的扩展,将 Date 转化为指定格式的String// 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位 ...
随机推荐
- java下文件遍历,与删除
package cn.stat.p1.file; import java.io.File; public class newfilelist { /** * @param args */ public ...
- 武汉科技大学ACM :1009: 零起点学算法63——弓型矩阵
Problem Description 输出n*m的弓型矩阵 Input 多组测试数据 每组输入2个整数 n和m(不大于20) Output 输出n*m的弓型矩阵,要求左上角元素是1,(每个元素占2个 ...
- 捷易拍与springMVC系统结合
1. 捷易拍高拍仪在jsp页面的调用 使用ActiveX插件的方式处理解决此问题,捷易拍公司提供了支持IE8以上的32位浏览器的插件,安装插件后,我们可以使用Object标签,使用高拍仪 注意: 1. ...
- 单源最短路径 hdu 2066
#include<string.h> //和prim类似#include<stdio.h> //prim所考虑的是节点与当前所建成的树的距离最小using namespace ...
- poj3254状压DP入门
G - 状压dp Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:65536KB 64bit ...
- 解决SurfaceView设置透明造成覆盖其他组件的替代方案
之前在项目里面绘制摇杆圆盘使用SurfaceView来实现,同时设置SurfaceView透明,但是这样会造成SurfaceView的组件会覆盖其他的组件,一般情况没有关系,而不一般的情况就是有类似上 ...
- VS2013配合EgretVS开发简单塔防游戏
VS2013配合EgretVS开发简单塔防游戏(1) - 环境配置 VS2013配合EgretVS开发简单塔防游戏(2) – 原型设计 VS2013配合EgretVS开发简单塔防游戏(3) – 精灵动 ...
- javascript各种专业名词
刚开始学javascript经常看到各种专业名词,在此整理一下个人的学习笔记: 直接量 直接量——就是程序中直接使用的数据值,如:88 //数字(String)"hello world ...
- (翻译玩)在使用flask-script的应用上使用gunicorn
在使用flask-script的应用上使用gunicorn 两周前,我强烈的想要学习一点新知识,像新的语言,新的框架之类的!好让我的大脑忙碌起来,寻找了一些日子后,我决定学习现在越来越流行的云应用平台 ...
- code first 尝试
建表: 1.先用EF连接数据库,配置connectionStrings <configSections> <!-- For more information on Entity Fr ...