当前位置: 首页 > news >正文

福州网页模板建站wordpress 推送公众号

福州网页模板建站,wordpress 推送公众号,深圳家居网站建设公司,wordpress 当前用户所有评论自定义一周的开始和结束,计算日期所在月的周数、所在月第几周、所在周的日期范围一. 方法使用二. 实现案例一. 方法使用 根据月开始日期星期几、月结束日期星期几,计算始周、末周占月的天数(每周周期段:上周六 —— 本周五&#x…

自定义一周的开始和结束,计算日期所在月的周数、所在月第几周、所在周的日期范围

  • 一. 方法使用
  • 二. 实现案例

一. 方法使用

根据月开始日期星期几、月结束日期星期几,计算始周、末周占月的天数(每周周期段:上周六 —— 本周五)

getStrEndDay(str_week, end_week) {// 始周占月的天数:开始周几(str_week) 距离 结束(周五) 有几天let str_num = 0;switch (str_week) {case 1:str_num = 5;break;case 2:str_num = 4;break;case 3:str_num = 3;break;case 4:str_num = 2;break;case 5:str_num = 1;break;case 6:str_num = 7;break;case 7:str_num = 6;break;}// 末周占月的天数:开始(周六) 距离 结束周几(end_week) 有几天let end_num = 0;switch (end_week) {case 1:end_num = 3;break;case 2:end_num = 4;break;case 3:end_num = 5;break;case 4:end_num = 6;break;case 5:end_num = 7;break;case 6:end_num = 1;break;case 0:end_num = 2;break;}return { str_num, end_num };
}

根据年月,获取每月有几周

getWeekCount(year, month) {// 获取天数var day_num = new Date(year, month, 0).getDate();// 该月第一天、最后一天const str_day = new Date().setFullYear(year, month - 1, 1);const end_day = new Date().setFullYear(year, month, 0);//该月第一周、最后一周const str_week = new Date(str_day).getDay();const end_week = new Date(end_day).getDay();// 该月减去第一周、最后一周的天数const numRes = this.getStrEndDay(str_week, end_week);const oth_day = day_num - numRes.end_num - numRes.str_num;// 总周数let week_num = oth_day / 7;if (numRes.str_num == 7) {week_num += 1;}if (numRes.end_num != 0) {week_num += 1;}return week_num;
}

根据年月日获取当前周

getCurWeek(year, month, day) {// 该月第一天、最后一天const str_day = new Date().setFullYear(year, month - 1, 1);const end_day = new Date().setFullYear(year, month, 0);//该月第一周、最后一周const str_week = new Date(str_day).getDay();const end_week = new Date(end_day).getDay();// 该月减去第一周的天数const numRes = this.getStrEndDay(str_week, end_week);const oth_day = day - numRes.str_num;// 第几周let cur_week = Math.ceil(oth_day / 7);if (numRes.str_num == 7) {cur_week += 1;}return cur_week;
}

根据年、月、周获取周的日期

getWeekTime(year, month, week) {// 获取天数var day_num = new Date(year, month, 0).getDate();// 该月第一天、最后一天const str_day = new Date().setFullYear(year, month - 1, 1);const end_day = new Date().setFullYear(year, month, 0);//该月第一周、最后一周const str_week = new Date(str_day).getDay();const end_week = new Date(end_day).getDay();const numRes = this.getStrEndDay(str_week, end_week);// 该周开始、结束日期let str_time = (week - 1) * 7 + 1;let end_time = week * 7;if (numRes.str_num != 7) {str_time += numRes.str_num;end_time += numRes.str_num;}let mm = Number(month);mm = mm < 10 ? "0" + mm : mm;str_time = str_time < 10 ? "0" + str_time : str_time;end_time = end_time < 10 ? "0" + end_time : end_time;let strDate = year + "-" + mm + "-" + str_time;let endDate = year + "-" + mm + "-" + end_time;if (Number(end_time) > day_num) {let mm1 = Number(mm) + 1 < 10 ? "0" + (Number(mm) + 1) : Number(mm) + 1;let last_num = Number(end_time) - day_num;last_num = last_num < 10 ? "0" + last_num : last_num;endDate = year + "-" + mm1 + "-" + last_num;}return {strDate,endDate};
}

二. 实现案例

<template><div>Home</div>
</template><script>
export default {data() {return {};},mounted() {// 自定义一周的开始和结束,计算日期所在月的周数、所在月第几周、所在周的日期范围const date = new Date(); //需要计算的日期const yy = date.getFullYear();const mm = (date.getMonth() + 1 + "").padStart(2, "0");const dd = (date.getDate() + "").padStart(2, "0");console.log(`计算日期:${yy}${mm}${dd}`);const week_count = this.getWeekCount(yy, mm);console.log(`${yy}${mm}月总共${week_count}`);const week_cur = this.getCurWeek(yy, mm, dd);console.log(`${yy}${mm}${dd}日属于本月第${week_cur}`);const days = this.getWeekTime(yy, mm, week_cur);console.log(`${yy}${mm}月第${week_cur}周日期段为${days.strDate} —— ${days.endDate}`);},methods: {// 根据月开始日期星期几、月结束日期星期几,计算始周、末周占月的天数(每周周期段:上周六 —— 本周五)getStrEndDay(str_week, end_week) {// 始周占月的天数:开始周几(str_week) 距离 结束(周五) 有几天let str_num = 0;switch (str_week) {case 1:str_num = 5;break;case 2:str_num = 4;break;case 3:str_num = 3;break;case 4:str_num = 2;break;case 5:str_num = 1;break;case 6:str_num = 7;break;case 7:str_num = 6;break;}// 末周占月的天数:开始(周六) 距离 结束周几(end_week) 有几天let end_num = 0;switch (end_week) {case 1:end_num = 3;break;case 2:end_num = 4;break;case 3:end_num = 5;break;case 4:end_num = 6;break;case 5:end_num = 7;break;case 6:end_num = 1;break;case 0:end_num = 2;break;}return { str_num, end_num };},// 根据年月,获取每月有几周getWeekCount(year, month) {// 获取天数var day_num = new Date(year, month, 0).getDate();// 该月第一天、最后一天const str_day = new Date().setFullYear(year, month - 1, 1);const end_day = new Date().setFullYear(year, month, 0);//该月第一周、最后一周const str_week = new Date(str_day).getDay();const end_week = new Date(end_day).getDay();// 该月减去第一周、最后一周的天数const numRes = this.getStrEndDay(str_week, end_week);const oth_day = day_num - numRes.end_num - numRes.str_num;// 总周数let week_num = oth_day / 7;if (numRes.str_num == 7) {week_num += 1;}if (numRes.end_num != 0) {week_num += 1;}return week_num;},// 根据年月日获取当前周getCurWeek(year, month, day) {// 该月第一天、最后一天const str_day = new Date().setFullYear(year, month - 1, 1);const end_day = new Date().setFullYear(year, month, 0);//该月第一周、最后一周const str_week = new Date(str_day).getDay();const end_week = new Date(end_day).getDay();// 该月减去第一周的天数const numRes = this.getStrEndDay(str_week, end_week);const oth_day = day - numRes.str_num;// 第几周let cur_week = Math.ceil(oth_day / 7);if (numRes.str_num == 7) {cur_week += 1;}return cur_week;},// 根据年、月、周获取周的日期getWeekTime(year, month, week) {// 获取天数var day_num = new Date(year, month, 0).getDate();// 该月第一天、最后一天const str_day = new Date().setFullYear(year, month - 1, 1);const end_day = new Date().setFullYear(year, month, 0);//该月第一周、最后一周const str_week = new Date(str_day).getDay();const end_week = new Date(end_day).getDay();const numRes = this.getStrEndDay(str_week, end_week);// 该周开始、结束日期let str_time = (week - 1) * 7 + 1;let end_time = week * 7;if (numRes.str_num != 7) {str_time += numRes.str_num;end_time += numRes.str_num;}let mm = Number(month);mm = mm < 10 ? "0" + mm : mm;str_time = str_time < 10 ? "0" + str_time : str_time;end_time = end_time < 10 ? "0" + end_time : end_time;let strDate = year + "-" + mm + "-" + str_time;let endDate = year + "-" + mm + "-" + end_time;if (Number(end_time) > day_num) {let mm1 = Number(mm) + 1 < 10 ? "0" + (Number(mm) + 1) : Number(mm) + 1;let last_num = Number(end_time) - day_num;last_num = last_num < 10 ? "0" + last_num : last_num;endDate = year + "-" + mm1 + "-" + last_num;}return {strDate,endDate};}}
};
</script>
http://www.yayakq.cn/news/93243/

相关文章:

  • 自己做网站出口延安网站建设报价
  • c2c的电子商务网站有哪些城乡住房建设部网站造价师网
  • 郑州威盟网站建设公司怎么样建设购物网站多少钱
  • 免备案的网站南充网站建设设计略奥
  • 注册公司网站的步骤网站设计策划书 模板
  • 辽宁住房建设部网站百度小程序开发工具下载
  • 微网站模板制作教程活动推广朋友圈文案
  • 广告平面设计网站适合设计师的网站编辑软件
  • h5在哪个网站中做网络推广服务合同
  • 外汇直播网站建设开发百度打网站名称就显示 如何做
  • 开一家网站建设公司wordpress 文章类型模板
  • 网站开发发展现状在中国怎么做国外网站
  • 哪些网站做的海报比较高大上检测设备技术支持东莞网站建设
  • 有道翻译网站 做翻译wordpress怎么改模版
  • 淘宝网站建设合同创建公司网站需要准备哪些素材
  • 做养生网站需要资质吗企业网站开发一般多少钱
  • 网站建设怎么建设企业网站排行
  • 织梦可以做相亲网站网站规划可以分成哪几步
  • 济南网站建设推广php网站开发是什么意思
  • 网站上传视频怎么做简单的公司网站系统
  • 建设注册管理中心网站如何建立一个网站的数据库文件
  • 做电脑网站用什么软件有哪些方面众筹网站怎么做
  • 网站怎么添加百度商桥花都网站建设
  • 专业网站优化软件设计师导航网站
  • 外贸常用网站建设眼镜网站风格
  • 网站建设 检查 通报绍兴seo排名
  • 宠物网站建设费用北京网站建设找德冿朴
  • c 如何拖控件做网站信息流广告图片
  • 朝阳公司做网站seo站点
  • 综合性电子商务网站有哪些百度托管运营哪家好