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

来源:互联网 发布:淘宝开店认证无法拍照 编辑:程序博客网 时间:2024/04/30 12:55

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/ 大非常的强大,官网上有大量的例子


0 0
原创粉丝点击