// 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. SharePoint对象模型性能考量

    转:http://blog.csdn.net/ma_jiang/article/details/6553373 部分常见用例场景都是关于显示和编辑SharePoint列表的--可惜,这也是我们看到很多 ...

  2. wcf 多个节点名出错

    无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置.请按名称指示首选的终结点配置部分. 原因是config节点中多了endpoint相 ...

  3. Java之 AtomicInteger

    AtomicInteger,一个提供原子操作的Integer的类.在Java语言中,++i和i++操作并不是线程安全的,在使用的时候,不可避免的会用到synchronized关键字.而AtomicIn ...

  4. C# 线程更新UI

    最方便的用法: private void ViewMsg(string msg)        { /* control.Invoke(new SetControlTextDelegate((ct,  ...

  5. 打印grid

    void PrintButtonClick(object sender, EventArgs e) { PrintPreviewDialog dlg = new PrintPreviewDialog( ...

  6. ashx文件结合ajax使用(返回json数据)

    ashx文件返回json数据: public void ProcessRequest(HttpContext context) { context.Response.ContentType = &qu ...

  7. BZOJ 2588: Spoj 10628. Count on a tree 主席树+lca

    分析:树上第k小,然后我想说的是主席树并不局限于线性表 详细分析请看http://www.cnblogs.com/rausen/p/4006116.html,讲的很好, 然后因为这个熟悉了主席树,真是 ...

  8. 利用Testng注释实现多线程并发测试

    Testng 是一款非常优秀的测试框架,真正从测试角度出发,为测试所想.在测试过程中我们经常会遇到对某一个场景做并发请求,主要想了解该程序在并发时是否会有异常或者没考虑到的其他情况,这时往往不是要做性 ...

  9. 【转+心得】WinDbg+VM9双机调试无法连接解决方案

    参考:http://www.52pojie.cn/forum.php?mod=viewthread&tid=203339 启动顺序为:先启动vmware里面的xp后(登录到桌面),再启动win ...

  10. Android 不能勾选 Project Build Target

    再勾选完project bulid target,从新返回这个页面,发现还是没有被勾选上. 从新刷新一下项目,原因是project.properties配置文件没有加载上. 下回导入的项目第一件事就是 ...