/**
* @description format the time
* @author xf.radish
* @param {String} format The format your want
* @param {String} lang The language
* @return {String} Return the format time
* @example
* var time = new Date();
* time.format('YYYY MMM dd , hh:mm:ss www','e');
*/ Date.prototype.format = function (format,lang) {
var o = {
'Y+': this.getFullYear(),//year
'M+': this.getMonth() + 1,//month
'w+': this.getDay(), //week
'd+': this.getDate(), //day
'h+': this.getHours(), //hour
'm+': this.getMinutes(), //minute
's+': this.getSeconds(), //second
'q+': Math.floor((this.getMonth() + 3) / 3), //quarter
'S+': this.getMilliseconds() //millisecond
};
var language={
e:{
'MMM' : 'null jan feb mar apr may jun jul aug sep oct nov dec'.split(' '),
'www' : 'sun mon tue wed thu fri sat'.split(' ')
},
z:{
'MMM' : 'null 一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月'.split(' '),
'www' : '星期日 星期一 星期二 星期三 星期四 星期五 星期六'.split(' ')
}
}
for (var k in o){
var reg='(' + k + ')';
       new RegExp(reg).test(format);
var r1=RegExp.$1;
if(r1.length == 3){
format=format.replace(r1,lang+'_'+r1+'_'+o[k]);
}else{
format=format.replace(r1,('00'+o[k]).substr(-r1.length));
}
};
format=format.replace(/(\w+)_(\w+)_(\w+)/g,function(match, r1, r2 ,r3){
try{
return language[r1][r2][r3];
}catch(e){
alert(e);
}
});
return format;
};

工具类 util.Date 日期类的更多相关文章

  1. java.util.Date日期类通过java语句转换成Sql(这里测试用的是oracle)语句可直接插入(如:insert into)的日期类型

    public void add(Emp emp) throws Exception{ QueryRunner runner = new QueryRunner(JdbcUtil.getDataSour ...

  2. 常用类--Date日期类,SimpleDateFormat日期格式类,Calendar日历类,Math数学工具类,Random随机数类

    Date日期类 Date表示特定的时间,精确到毫秒; 构造方法: public Data() public Date(long date) 常用方法: public long getTime() pu ...

  3. Date日期类,Canlendar日历类,Math类,Random随机数学类

    Date日期类,SimpleDateFormat日期格式类 Date  表示特定的时间,精确到毫秒 常用方法 getTime() setTime() before() after() compareT ...

  4. javascript Date日期类

      四.Date日期类 迁移时间:2017年5月27日18:43:02 Author:Marydon (一)对日期进行格式化(日期转字符串) 自定义Date日期类的format()格式化方法 方式一: ...

  5. Java常用类:包装类,String,日期类,Math,File,枚举类

    Java常用类:包装类,String,日期类,Math,File,枚举类

  6. java Date日期类和SimpleDateFormat日期类格式

    ~Date表示特定的时间,精确到毫秒~构造方法:public Date()//构造Date对象并初始化为当前系统的时间public Date(long date) //1970-1-1 0:0:0到指 ...

  7. Date日期类 Calendar日历类 完成可视化日历

    package com.test; import java.text.DateFormat; import java.text.ParseException; import java.text.Sim ...

  8. Java可视化日历(Date类、DATe Format类、Calendar类综合运用),开发可视化日历小程序

    Java时间日期类综合运用,开发可视化日历小程序 由键盘输入指定格式的日期,打印这个月的日历 1.代码 import java.text.DateFormat; import java.text.Pa ...

  9. C++实现Date日期类

    定义一个Date类,包含三个属性年.月.日 实现了如下功能: 年月日的增加.减少:2017年10月1日加上100个月30天是2025年5月31日 输出某天是星期几:2017年10月1日是星期日 判断某 ...

随机推荐

  1. Linux环境fork()函数详解

    Linux环境fork()函数详解 引言 先来看一段代码吧, 1 #include <sys/types.h> 2 #include <unistd.h> 3 #include ...

  2. Javascript 封装问题

    Javascript 封装问题 为什么会用这样一个题目呢,这是要说封装的什么问题,本文并不讲高深的封装理论,只是解决一个小问题. 问题来源 今天在百度知道上闲逛,遇到一个网友的问题,问题如下,问题的地 ...

  3. 查找算法---find运算,find_first_of的使用

    查找算法---find运算,find_first_of的使用 一.find运算 假设有一个int型的vector对象,名为vec,我们想知道其中是否包含某个特定值. 解决这个问题最简单的方法时使用标准 ...

  4. Archives for the category: Fisheye/Crucible

    Archives for the category: Fisheye/Crucible Introducing FishEye and Crucible 3.0 – Search, visualize ...

  5. [置顶] iOS学习笔记47——图片异步加载之EGOImageLoading

    上次在<iOS学习笔记46——图片异步加载之SDWebImage>中介绍过一个开源的图片异步加载库,今天来介绍另外一个功能类似的EGOImageLoading,看名字知道,之前的一篇学习笔 ...

  6. 菜单工具栏wxPython菜单与工具栏基础示例

    这两天一直在学习菜单工具栏之类的问题,上午正好有机会和大家讨论一下. 1.基本的api介绍 Package wx :: Class Menu Type Menu Method Summary Menu ...

  7. 在android里用ExpandableListView实现二层和三层列表

    转载自http://www.cnblogs.com/nuliniaoboke/archive/2012/11/13/2767957.html 二层列表是直接用androidAPI中的Expandabl ...

  8. easyui datebox 时间限制,datebox开始时间限制结束时间,datebox截止日期比起始日期大

    easyui datebox 时间限制,datebox开始时间限制结束时间,datebox截止日期比起始日期大 >>>>>>>>>>> ...

  9. https时代来了,你却还一无所知?

    本文作者:茄果,专注前端开发领域,更多文章请关注知乎专栏<前端小事> 现在打开各大知名网站,你有没有发现地址栏都已经加了个绿色的小锁? 是的,这就是https,这就是https的时代. 然 ...

  10. 微信内嵌H5网页 解决js倒计时失效

    项目要求:将H5商城页面嵌套到公司微信公众号里 项目本身的开发跟移动端网页并无太多差异,只是这昨天遇到一个问题,说是棘手,到也简单. 用户下单后,在选择支付方式页面,有个倒计时的逻辑(从下单时开始计算 ...