// 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的更多相关文章

  1. 新手,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 ...

  2. 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 ...

  3. OSG3.40 编译时,无法打开输入文件“optimized.lib”

    解决方案: 正常情况下,下图中会多出一项:ZLIB_LIBRARY_RELEASE,之后屡次编译,都提示"无法打开输入文件"optimized.lib"" 因为 ...

  4. Eclipse部署Maven web项目到tomcat服务器时,没有将lib下的jar复制过去的解决办法

    我们在做web开发是,经常都要在eclipse中搭建web服务器,并将开发中的web项目部署到web服务器进行调试,在此,我选择的是tomcat服务器.之前部署web项目到tomcat进行启动调试都很 ...

  5. 解决VS2015安装后stdio.h ucrtd.lib等文件无法识别问题

    今天突然想在windows上装个 VS2015 玩玩,结果遇到了如下bug:安装完 VS2015 后,直接新建项目->win32控制台->运行,结果报错!"无法打开包括文件: & ...

  6. 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 ...

  7. 通过dll或def文件提取lib导入库文件

    很多时候第三方库或其他项目提供的库多数会以动态库的形式提供dll以及相应的lib导入库.头文件,不过也有的只是提供dll和头文件,或者也提供了def模块定义(用于导出函数)文件,此时若使用将不得不调用 ...

  8. 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: *** [ ...

  9. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    有时候,当我们使用"mysql"."mysqladmin"."mysqldump"等命令管理数据库时,服务器抛出类似如下错误: 一.错误现场 ...

随机推荐

  1. vijosP1016 北京2008的挂钟

    vijosP1016 北京2008的挂钟 题目链接:https://vijos.org/p/1016 [思路] Dfs. 对操作搜索更加优秀,所以采用搜索每一个操作的使用次数,因为操作数为4则相当于没 ...

  2. [Locked] Unique Word Abbreviation

    Unique Word Abbreviation An abbreviation of a word follows the form <first letter><number&g ...

  3. 2015 CCPC-C-The Battle of Chibi (UESTC 1217)(动态规划+树状数组)

    赛后当天学长就说了树状数组,结果在一个星期后赖床时才有了一点点思路…… 因为无法提交,不确定是否正确..嗯..有错希望指出,谢谢... 嗯..已经A了..提交地址http://acm.uestc.ed ...

  4. 在YII中使用Redis等缓存

    Yii AR 单行数据-自动缓存机制 | LOCKPHP Yii AR 单行数据-自动LOG机制 CActiveRecordBehavior进阶 | LOCKPHP 缓存 - 权威指南 - Yii F ...

  5. IE-二级网页打不开

    无法打开二级链接的处理方法是重新注册如下的DLL文件: 在开始—运行里输入: regsvr32 Shdocvw.dll regsvr32 Shell32.dll(注意这个命令,先不用输) regsvr ...

  6. Spring源码入门——AnnotationBeanNameGenerator解析

    ---恢复内容开始--- 接上篇,上篇解析了DefaultBeanGenerator生成bean name的过程(http://www.cnblogs.com/jason0529/p/5272265. ...

  7. firefox和chrome对于favicon.ico关于content-security-policy的不同处理

    1.favicon.ico是网站的title图标 2.在设置CSP时,举例如下,表示只允许来源为https://my.alipay.com的图片,如果不是,则向指定的url(report.php)发出 ...

  8. Delphi- 内置数据库的使用例子BDE

    以前开发时经常使用一些大型的数据库,像这样小的数据库还是前段时间才看到.看看Delphi怎么使用内置的数据库, 先在BDE里拉两个数据库控件.DataBase和Table,然后再拉两个数据库控件Dat ...

  9. Oracle--SQL Developer创建连接及使用

    安装好Oracle之后,有几种方式可以来管理Oracle中的数据库,首先就是登陆网页版的界面:https://localhost:1158/em,这种方式管理的东西太多,使用起来有点不方便,第二种方式 ...

  10. window下 Mongodb无法访问28107的有关问题(转)

    原文链接:http://www.myexception.cn/go/1956868.html Mongodb无法访问28107的问题 0:环境 os:window7 64位 mongodb版本:3.0 ...