您现在的位置:首页 >> JS&Jq >> 内容

jquery时间格式化插件

时间:2014-8-15 13:36:00 点击:

  核心提示:1插件的代码:?1?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495...
1
 
插件的代码:
?
1
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(function($){
    $.formatDate = function(pattern,date){
        //如果不设置,默认为当前时间
        if(!date) date = new Date();
        if(typeof(date) ==="string"){
             if(date=="")  date = new Date();
              else  date = new Date(date.replace(/-/g,"/"));
        }  
        /*补00*/
        var toFixedWidth = function(value){
             var result = 100+value;
             return result.toString().substring(1);
        };
         
        /*配置*/
        var options = {
                regeExp:/(yyyy|M+|d+|h+|m+|s+|ee+|ws?|p)/g,
                months: ['January','February','March','April','May',
                         'June','July', 'August','September',
                          'October','November','December'],
                weeks: ['Sunday','Monday','Tuesday',
                        'Wednesday','Thursday','Friday',
                            'Saturday']
        };
         
        /*时间切换*/
        var swithHours = function(hours){
            return hours<12?"AM":"PM";
        };
         
        /*配置值*/
        var pattrnValue = {
                "yyyy":date.getFullYear(),                      //年份
                "MM":toFixedWidth(date.getMonth()+1),           //月份
                "dd":toFixedWidth(date.getDate()),              //日期
                "hh":toFixedWidth(date.getHours()),             //小时
                "mm":toFixedWidth(date.getMinutes()),           //分钟
                "ss":toFixedWidth(date.getSeconds()),           //秒
                "ee":options.months[date.getMonth()],           //月份名称
                "ws":options.weeks[date.getDay()],              //星期名称
                "M":date.getMonth()+1,
                "d":date.getDate(),
                "h":date.getHours(),
                "m":date.getMinutes(),
                "s":date.getSeconds(),
                "p":swithHours(date.getHours())
        };
         
        return pattern.replace(options.regeExp,function(){
               return  pattrnValue[arguments[0]];
        });
    };
     
})(jQuery);

 

插件使用:

前提要有一个jquery-1.8.3.js

?
1
<!-- jquery的使用 -->
?
1
2
3
4
5
6
7
8
<script type="text/javascript" src="jquery-1.8.3.js"/></script>
<script type="text/javascript" src="jquery.dateformat.js"></script>
<script type="text/javascript">
$(function($){
     var time = new Date("2014-01-01 13:20:30");
      console.info($.formatDate("yyyy-MM-dd hh:mm:ss ws ee","2013-1-1 13:20:30"));
});
</script>


?
1
 


效果:

n块エky

作者:不详 来源:网络
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 青春网络编程技术(www.qcfupo.com) © 2020 版权所有 All Rights Reserved.
  • Powered by qcfupo! V3.0sp1
  • 百度友情链接: 百家乐[www.chinawestnews.net/aomenbaijiale/] 赌博网[www.chinawestnews.net/amdbwz/] 海立方[www.bjl.gov.cn/bjgylc/] 娱乐城[www.gtxrmzf.gov.cn/mapai/] 娱乐城[www.hfsf.gov.cn/yfgj/] 威尼斯人[www.hllinkou.gov.cn/baijile/] 澳门威尼斯[www.jjwgj.gov.cn/wnsr/] 888真人[www.lagm.gov.cn/888zhenren/] 百乐坊[www.laoling.gov.cn/blfylc/] 现金网[www.longyu.gov.cn/xjw/] 百家乐[www.chinawestnews.net/ambjl/] 新葡京娱乐场[www.sjzedu.gov.cn/jsylc/] 时时彩[www.snjw.gov.cn/ssc/] 赌博[www.chinawestnews.net/aomendubo/]