nodejs 周操作

来源:互联网 发布:淘宝特价 编辑:程序博客网 时间:2024/06/03 23:00
var Rangedate = require('rangedate');Date.prototype.normalize = function () {    return this.toLocaleDateString() + " 00:00:00";};Date.prototype.otherDay = function (day) {    return new Date(this.getFullYear(), this.getMonth(), this.getDate() + day, this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds());};Date.prototype.durationDay = function (day) {    var s = new Date(this.normalize());    return Rangedate(s, day).map(function (data) {        return new Date(data.normalize());    });};function getMondayByToday(today) {    var _weekDay = today.getDay();//0,1,2,3,4,5,6    _weekDay = (_weekDay == 0) ? (7) : _weekDay;    var mondayDateThisWeek = today.otherDay(-(_weekDay - 1));    return mondayDateThisWeek;}function getWeekDurationDayPoolByToday(today) {    var monday = getMondayByToday(today);    var sunday = monday.otherDay(6);    var weekPool = monday.durationDay(sunday);    return weekPool;}function theWeekOfYear(curDate) {    /*     date1是当前日期     date2是当年第一天     d是当前日期是今年第多少天     用d + 当前年的第一天的周差距的和在除以7就是本年第几周     */    var a = curDate.getFullYear();    var b = curDate.getMonth() + 1;    var c = curDate.getDate();    var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1),        d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000);    return Math.ceil(        (d + ((date2.getDay() + 1) - 1)) / 7);}var weekPool = getWeekDurationDayPoolByToday(new Date());console.log("weekPool:",weekPool);console.log(theWeekOfYear(new Date("2016-2-1")))

1 0
原创粉丝点击