datejs lib
// Get today's date
Date.today(); // Add 5 days to today
Date.today().add(5).days(); // Get Friday of this week
Date.friday(); // Get March of this year
Date.march(); // Is today Friday?
Date.today().is().friday(); // true|false // What day is it?
Date.today().getDayName(); [/js] Everything ok? A little out of breath? Soooo sorry. Now, some Date Assassin exercises.
[js]
// Get the first Monday of the year
Date.january().first().monday() // Get the last Friday of the year
Date.dec().final().fri() // Set a date to the 15th of the current month at 4:30 PM,
// then add 90 days and make sure that date is a weekday,
// else move to the next weekday.
var d1 = Date.today()
.set({ day: 15, hour: 16, minute: 30 })
.add({ days: 90 })
if (!d1.isWeekday()) {
d1.next().monday();
}
[/js]
How about letting your users enter a few dates? Say into an <input> field or date picker? Included with the Datejs library is a powerful replacement for the native JavaScript Date parser. The following examples all start with a String value that we convert into a Date object.
[js]
// Lets start simple. "Today"
Date.parse('today'); // How about tomorrow?
Date.parse('tomorrow'); // July 8?
Date.parse('July 8'); // With a year?
Date.parse('July 8th, 2007'); // And time?
Date.parse('July 8th, 2007, 10:30 PM'); // Get the date, move to Monday (if not already Monday),
// then alert the date to the user in a different format.
var d1 = Date.parse('8-Jul-2007');
if (!d1.is().monday()) {
d1.last().monday();
}
alert(d1.toString('dddd, MMMM d, yyyy'));
[/js] The library also includes some Number fun. In order to execute functions directly on JavaScript Number objects, the number must be wrapped in parentheses. This is a requirement of JavaScript. If the number is declared first, the parentheses are not required.
[js]
// Get a date 3 days from now
(3).days().fromNow(); // 6 month ago
(6).months().ago(); // 12 weeks from now
var n = 12;
n.weeks().fromNow(); // Get a date 30 days after a user supplied date
var d1 = Date.parse('07.15.2007');
var d2 = (30).days().after(d1);
[/js]
详细文档:
http://code.google.com/p/datejs/wiki/APIDocumentation
datejs lib的更多相关文章
- 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件“libboost_thread-vc140-mt-gd-1_63.lib“的解决办法
		1,到官网下载最新的boost,www.boost.org 这里我下载的1-63版本. 2,安装,解压后运行bootstrap.bat文件.稍等一小会就OK. 3,编译boost库.注意一定要使用VS ... 
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
		ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock 通过终端安装程序sudo apt-get install xxx时出错:E: Could not ... 
- OSG3.40 编译时,无法打开输入文件“optimized.lib”
		解决方案: 正常情况下,下图中会多出一项:ZLIB_LIBRARY_RELEASE,之后屡次编译,都提示"无法打开输入文件"optimized.lib"" 因为 ... 
- Eclipse部署Maven web项目到tomcat服务器时,没有将lib下的jar复制过去的解决办法
		我们在做web开发是,经常都要在eclipse中搭建web服务器,并将开发中的web项目部署到web服务器进行调试,在此,我选择的是tomcat服务器.之前部署web项目到tomcat进行启动调试都很 ... 
- 解决VS2015安装后stdio.h ucrtd.lib等文件无法识别问题
		今天突然想在windows上装个 VS2015 玩玩,结果遇到了如下bug:安装完 VS2015 后,直接新建项目->win32控制台->运行,结果报错!"无法打开包括文件: & ... 
- locate: can not open `/var/lib/mlocate/mlocate.db': No such file or directory
		# locate zabbix locate: can not open `/var/lib/mlocate/mlocate.db': No such file or directory locate ... 
- 通过dll或def文件提取lib导入库文件
		很多时候第三方库或其他项目提供的库多数会以动态库的形式提供dll以及相应的lib导入库.头文件,不过也有的只是提供dll和头文件,或者也提供了def模块定义(用于导出函数)文件,此时若使用将不得不调用 ... 
- make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl] 错误 1,make: *** [out/host/linux-x86/obj/lib/libESR_Portable.so] 错误 1
		错误3: g++: g++: selected multilib '32' not installed selected multilib '32' not installed make: *** [ ... 
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
		有时候,当我们使用"mysql"."mysqladmin"."mysqldump"等命令管理数据库时,服务器抛出类似如下错误: 一.错误现场 ... 
随机推荐
- Xcode 不提示, 引用失效等情况
			在编写xcode的项目的时候出现过代码不高亮的症状,而且所有的warning都不再提示,include的内容也显示symbol not found,非常奇怪,解决方案如下: 方法一: 1.把.pch里 ... 
- 兼容ie\firefox\chrome的cursor
			cursor:hand 与 cursor:pointer 的效果是一样,都像手形光标. 但用FireFox浏览时才注意到使用cursor:hand在FireFox.chorme里并被支持.cursor ... 
- Chrome 控制台console的用法(学了之后对于调试js可是大大有用的哦)
			大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能大家对co ... 
- MsoShapeType /InlineShape枚举
			指定形状的类型或形状范围. 名称 值 说明 msoAutoShape 1 自选图形. msoCallout 2 标注. msoCanvas 20 画布. msoChart 3 图. msoCommen ... 
- linux tar 解压命令总结
			把常用的tar解压命令总结下,当作备忘: tar -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其 ... 
- xampp 访问出现New XAMPP security concept 或者 新しいXAMPPのセキュリティコンセプト
			出现如下错误: 新しいXAMPPのセキュリティコンセプト: は.要求されたオブジェクトへのアクセスは.ローカルネットワークから入手可能です. この設定は.ファイル"で設定することができますの ... 
- 跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量
			跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量 Lead Measurement: Example for the application of the measure object in ... 
- linux和Dos下换行符转换
			一.windows的文件到linux下的转换方法: 1. 用sed命令替换 sed -e 's/^M//g' original.txt > target.txt (注意^M 在Linux/Uni ... 
- POJ-3017 Cut the Sequence DP+单调队列+堆
			题目链接:http://poj.org/problem?id=3017 这题的DP方程是容易想到的,f[i]=Min{ f[j]+Max(num[j+1],num[j+2],......,num[i] ... 
- pes and ts stream, how to convert
			http://stackoverflow.com/questions/4145575/transport-stream-mpeg-file-fromat What you are probably w ... 
