最近使用js做表格,遇到要将根据日期得出work week的需求,网上查了一些相关代码,这里修改下并做下记录
{ display: ‘Work_Week‘, name: ‘create_time‘, width: 80, render: function (item) { return getYearWeek(item.create_time); } }
//获取一年中第几周 function getYearWeek(date) { date = formatTimebytype(date, ‘yyyy-MM-dd‘);//将日期转换成yyyy-mm-dd格式 date = new Date(date); var date2 = new Date(date.getFullYear(), 0, 1); var day1 = date.getDay(); if (day1 == 0) day1 = 7; var day2 = date2.getDay(); if (day2 == 0) day2 = 7; d = Math.round((date.getTime() - date2.getTime() + (day2 - day1) * (24 * 60 * 60 * 1000)) / 86400000); return Math.ceil(d / 7) + 1; }
原文地址:https://www.cnblogs.com/Alvis-Lv/p/10986306.html
时间: 2024-10-04 18:39:14