CoffeeScript 找到上一个月(或下一个月)


本文整理自网络,侵删。

找到上一个月(或下一个月)

问题

你需要计算相关日期范围例如“上一个月”,“下一个月”。

解决方案

添加或减去当月的数字,JavaScript的日期构造函数会修复数学知识。

# these examples were written in GMT-6
# Note that these examples WILL work in January!
now = new Date
# => "Sun, 08 May 2011 05:50:52 GMT"

lastMonthStart = new Date 1900+now.getYear(), now.getMonth()-1, 1
# => "Fri, 01 Apr 2011 06:00:00 GMT"

lastMonthEnd = new Date 1900+now.getYear(), now.getMonth(), 0
# => "Sat, 30 Apr 2011 06:00:00 GMT"

讨论

JavaScript的日期对象会处理下溢和溢出的月和日,并将相应调整日期对象。例如,你可以要求寻找三月的第42天,你将获得4月11日。

阅读剩余部分

相关阅读 >>

CoffeeScript 创建 jquery 插件

CoffeeScript 找到一个月中的最后一天

CoffeeScript for 循环

CoffeeScript 策略模式

CoffeeScript 使用 html 命名实体替换 html 标签

CoffeeScript coffeescrip 的 type 函数

CoffeeScript 清理字符串前后的空白符

CoffeeScript 模板方法模式

CoffeeScript 反转数组

CoffeeScript 生成随机数

更多相关阅读请进入《CoffeeScript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...