123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- function getDay(day) {
- var today = new Date()
-
- var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day
-
- today.setTime(targetday_milliseconds) //注意,这行是关键代码
-
- var tYear = today.getFullYear()
-
- var tMonth = today.getMonth()
-
- var tDate = today.getDate()
-
- tMonth = doHandleMonth(tMonth + 1)
-
- tDate = doHandleMonth(tDate)
-
- return tYear + '-' + tMonth + '-' + tDate
- }
-
- function doHandleMonth(month) {
- var m = month
-
- if (month.toString().length == 1) {
- m = '0' + month
- }
-
- return m
- }
- export { getDay }
- Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (var k in o) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- }
- }
- return fmt;
- }
- export function allWeeks(now_month) {
- let week_array = [];
- let today = new Date(Date.parse(now_month));
- let year = today.getFullYear();
- let month = today.getMonth();
- let i = 0;
- let start = new Date(year, month, 1); // 得到当月第一天
- let end = new Date(year, month + 1, 0); // 得到当月最后一天
- let start_day = start.getDay(); // 当月第一天是周几
- console.log(start.format("yyyy-MM-dd"), end.format("yyyy-MM-dd")); // 每月的起始日期
- switch (start_day) {
- case 0:
- i = 0 - 1;
- break;
- case 1:
- i = 0 - 2;
- break;
- case 2:
- i = 0 - 3;
- break;
- case 3:
- i = 0 - 4;
- break;
- case 4:
- i = 0 - 5;
- break;
- case 5:
- i = 1;
- break;
- case 6:
- i = 0;
- break;
- }
- while (new Date(year, month, i + 6) <= end) {
- week_array.push([new Date(year, month, i).format("yyyy-MM-dd"),
- new Date(year, month, i + 6).format("yyyy-MM-dd")
- ])
- i += 7;
- }
- return week_array;
- }
|