DDR爱好者之家 Design By 杰米
1、比较两个日期先后
var x = new Date('2015-05-25'); var y = new Date('2015-05-25'); if (x.getTime() == y.getTime()) { It'll be true; }
2、是否在两个日期之间
var beforeSpringDate, afterSpringDate; for (var i = 0; i < springFestivalDays.length; i++) { beforeSpringDate = new Date(springFestivalDays[i]); beforeSpringDate.setDate(beforeSpringDate.getDate() - 4); afterSpringDate = new Date(springFestivalDays[i]); afterSpringDate.setDate(afterSpringDate.getDate() + springFestivalPeriod - 1); if (time >= beforeSpringDate.getTime() && time <= afterSpringDate.getTime()) { result = true; break; } }
3、一行代码判断是否是闰年
var input = new Date();new Date(input.getFullYear(), 1, 29).getDate() === 29 false var input = new Date(2012,1,1);new Date(input.getFullYear(), 1, 29).getDate() === 29 true var input = new Date(2013,1,1);new Date(input.getFullYear(), 1, 29).getDate() === 29 false var input = new Date(2014,1,1);new Date(input.getFullYear(), 1, 29).getDate() === 29 false var input = new Date(2014,5,1);new Date(input.getFullYear(), 1, 29).getDate() === 29 false var input = new Date(2014,6,1);new Date(input.getFullYear(), 1, 29).getDate() === 29 false var input = new Date(2016,6,1);new Date(input.getFullYear(), 1, 29).getDate() === 29 true var input = new Date(2000,6,1);new Date(input.getFullYear(), 1, 29).getDate() === 29 true
4、判断重大节日(国庆、春节)前后一周状态
var holiday = {}; function inNationalDay(date) { var result = { beforeNationalDay: false, duringNationalDay: false }; if (date) { var month = date.getMonth() + 1, day = date.getDate(); if (month == 9 && (day >= 24 && day <= 30)) { result.beforeNationalDay = true; } else if(month == 10 && (day >= 1 && day <= 7)) { result.duringNationalDay = true; } } return result; } function inSpringFestival(date) { var result = { beforeSpringFestival: false, duringSpringFestival: false }; if (date) { // set GMT+0800 hours(set china hour +8) date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 8); var time = date.getTime(); var springFestivalDays = ['2015-02-19', '2016-02-08', '2017-01-28', '2018-02-16', '2019-02-05', '2020-01-25', '2021-02-12', '2022-02-01', '2023-01-22', '2024-02-10']; var springDay, springDate, beforeSpringDate, afterSpringDate; for (var i = 0; i < springFestivalDays.length; i++) { springDay = springFestivalDays[i]; springDate = new Date(springDay); beforeSpringDate = new Date(springDay); beforeSpringDate.setDate(beforeSpringDate.getDate() - 7); afterSpringDate = new Date(springDay); afterSpringDate.setDate(afterSpringDate.getDate() + 7); if (time >= beforeSpringDate.getTime() && time < springDate.getTime()) { result.beforeSpringFestival = true; break; } else if (time >= springDate.getTime() && time < afterSpringDate.getTime()) { result.duringSpringFestival = true; break; } } } return result; } holiday.cache = { lastUpdateDate: null, beforeHoliday: false, duringHoliday: false }; holiday.checkHoliday = function() { var now = new Date(); if (!holiday.cache.lastUpdateDate) { holiday.cache.lastUpdateDate = now; var nationalDayResult = inNationalDay(now); var springFestivalResult = inSpringFestival(now); holiday.cache.beforeHoliday = nationalDayResult.beforeNationalDay || springFestivalResult.beforeSpringFestival; holiday.cache.duringHoliday = nationalDayResult.duringNationalDay || springFestivalResult.duringSpringFestival; } else { var lastUpdateDate = holiday.cache.lastUpdateDate; var cacheDate = lastUpdateDate.getFullYear() + '' + lastUpdateDate.getMonth() + '' + lastUpdateDate.getDate(); var nowDate = now.getFullYear() + '' + now.getMonth() + '' + now.getDate(); if (cacheDate != nowDate) { holiday.cache.lastUpdateDate = now; var nationalDayResult = inNationalDay(now); var springFestivalResult = inSpringFestival(now); holiday.cache.beforeHoliday = nationalDayResult.beforeNationalDay || springFestivalResult.beforeSpringFestival; holiday.cache.duringHoliday = nationalDayResult.duringNationalDay || springFestivalResult.duringSpringFestival; } } }; module.exports = holiday;
5、判断星期几
<SCRIPT> var s = '2011-11-17'; alert( "今天星期 "+"天一二三四五六 ".charAt(new Date(s).getDay())); alert("星期 " + new Date(s).getDay()); </SCRIPT>
也可以这样:
var weekDay = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; var dateStr = "2008-08-08"; var myDate = new Date(Date.parse(dateStr.replace(/-/g, "/"))); alert(weekDay[myDate.getDay()]);
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]