Last active
September 25, 2017 08:45
-
-
Save fanfeilong/cbff8332a4d516874253c75fca1ec2be to your computer and use it in GitHub Desktop.
周/星期 转 日期 markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDateOfISOWeek(y,w,i) { | |
var simple = new Date(y, 0, 1 + (w - 1) * 7+i); | |
var dow = simple.getDay(); | |
var ISOweekStart = simple; | |
if (dow <= 4) | |
ISOweekStart.setDate(simple.getDate() - simple.getDay() + 1); | |
else | |
ISOweekStart.setDate(simple.getDate() + 8 - simple.getDay()); | |
return ISOweekStart; | |
} | |
function weekDate(y,w,i) { | |
let d = 1 + (w - 1) * 7+i; | |
//console.log(d); | |
var simple = new Date(y, 0, d); | |
return simple; | |
} | |
let c = {}; | |
for(let w=0;w<19;w++){ | |
let days = []; | |
for(let i=1;i<=5;i++){ | |
let week = w+36; | |
let z = weekDate(2017,week, i); | |
let m = z.getMonth()+1; | |
let d = z.getDate(); | |
days.push(`${m}`.padStart(2)+`-${d}`.padEnd(2)); | |
} | |
c[w+2] = days; | |
} | |
console.log(`| 周 | 星期一| 星期二| 星期三| 星期四| 星期五|`); | |
console.log(`| :--|:--| :--|:--|:--|:--|`); | |
for(let w in c){ | |
let days = c[w]; | |
console.log(`|${w}|${days[0]}|${days[1]}|${days[2]}|${days[3]}|${days[4]}|`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment