您的位置:首页 > Web前端 > JavaScript

2个牛逼的js处理日期和时间的库

2015-01-30 10:33 232 查看
1.小牛date.format.js 地址:http://blog.stevenlevithan.com/archives/date-time-format 下载:http://stevenlevithan.com/assets/misc/date.format.js

具体使用上面有详细的例子,下面贴一些我测试的代码:

var now = new Date();

                //1/29/15
                console.log("m/dd/yy:  " + now.format("m/dd/yy"));

                //Thursday, January 29th, 2015, 5:20:40 PM
                var cc = dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
                console.log('dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT"):  ' + cc);

                //2015-01-29T17:20:40
                console.log("isoDateTime:  " + now.format("isoDateTime"));

                //17:20! Can't touch this!
                dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
                console.log("dateFormat.masks:   " + now.format("hammerTime"));
                
                //Saturday, June 9, 2007
                console.log('dateFormat("Jun 9 2007", "fullDate"):   ' + dateFormat("Jun 9 2007", "fullDate"));

                //Thu Jan 29 2015 17:29:36
                console.log('now.format():   ' + now.format());

                //Thu Jan 29 2015 17:29:36
                console.log('dateFormat():   ' + dateFormat());

                //5:29:42 PM GMT+0800
                console.log('dateFormat("longTime"):   ' + dateFormat("longTime"));

                //9:29:36 AM UTC
                console.log('dateFormat(now, "longTime", true):   ' + dateFormat(now, "longTime", true));
                //9:29:36 AM UTC
                console.log('now.format("longTime", true):   ' + now.format("longTime", true));

                //9:29:36 AM UTC
                console.log('now.format("UTC:h:MM:ss TT Z"):    ' + now.format("UTC:h:MM:ss TT Z"));

                //2015-01-29 17:29:36
                console.log(dateFormat(now, "yyyy-mm-dd HH:MM:ss"));
ps:UTC是国际通用时间格式

2.大牛 Moment.js ,地址:http://momentjs.com/docs/ 下载:https://github.com/moment/moment/ 大非常的强大,官网上有大量的例子
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: