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 个占位 ...
随机推荐
- uva12489 Combating cancer(树同构)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud https://uva.onlinejudge.org/index.php?opt ...
- runtime error ?
程序运行时错误(运行时出错就是出现在程序运行过程中的),有很多种: 比如:溢出.内存泄露.死循.乱用指针.数组越界(数组开小了?).除以0错误.递归太深层(系统暴栈了)
- html Table实现表头固定
最近一直在搞前台琐碎的东西,也学习了一下linux,没有时间对新的东西进行深入的研究和学习,没有写博客,不过归咎其原因还是在于自己的惰怠. 废话不多说,今天想将一个前台页面设计的一个小东西分享一下,那 ...
- TreeMap Red-Black tree
本文以Java TreeMap为例,从源代码层面,结合详细的图解,剥茧抽丝地讲解红黑树(Red-Black tree)的插入,删除以及由此产生的调整过程. 总体介绍 之所以把TreeSet和TreeM ...
- Ajax实现三级联动(0520)
查询数据库中的chinastates表,通过父级代号查询相应省市区. 实现界面: 在js页面实现三级联动 在JQuery中调用Ajax方法(引用JQuery文件一定放在最上面) 用插件的形式,创建三个 ...
- php提取身份证号码中的生日日期以及验证是否为未成年人的函数
php 提取身份证号码中的生日日期以及确定是否成年的一个函数.可以同时确定15位和18位的身份证,经本人亲测,非常好用,分享函数代码如下: <?php //用php从身份证中提取生日,包括15位 ...
- JavaScript电话号码正则
var telNumRE = /^((\d{11})|(\d{3,4}-)*(\d{7,8})+(-\d{1,4})*|(\d{5}))$/; 可以截取以下内容: 11位手机号:18911931207 ...
- 内核参数优化之2-1 tcp/ip 标志位报文解析
以下内容纯属虚构,切勿轻易相信! 众所周知,tcp/ip三次握手和四次挥手,均由syn/ack/fin三个标志位报文决定,但是这三个标志位报文,并不是说在构建连接的时候只发送一次的,因为协议不知道网络 ...
- Scala学习笔记--Akka
待完成 http://www.gtan.com/akka_doc/ http://my.oschina.net/mingdong/blog/297972 http://www.jdon.com/con ...
- epoll函数及三种I/O复用函数的对比
epoll函数 #include <sys/epoll.h>int epoll_create(int size)int epoll_ctl(int epfd, int op, int fd ...