简单日历实例

tanzh 2023-8-19 832

import console; 
io.open()

//简单日历实例

getMonthDays = function(year,month){
	var startDate = year++"/"++month++"/"++"1"; //当月1日
	var endDate = time(startDate).addmonth(1).addday(-1); //当月末
	return endDate.diffday(time(startDate))+1; //当月天数
}

year = 2023;
for(month=1;12;1){
	io.stdout.write(year++"年"++month++"月",'\n');
	days = getMonthDays(year,month); //月天数
	spaceFlag = 0; //前空列
	for(day=1;days;1){
		currDate = string.join({year,month,day},"/");
		ymd = tostring(time(time(currDate),"%Y%m%d"));
		week = time(currDate).dayofweek:7; //星期,tm[9]
		if (!spaceFlag and week>1) {
			for(k=1;week-1;1) io.stdout.write("        "," "," "," ");
			spaceFlag = 1;
		}
		if ymd=tostring(time(time(),"%Y%m%d")) io.stdout.write(ymd,"*",tostring(week)," ");
		else io.stdout.write(ymd," ",tostring(week)," ");
		if week=7 io.stdout.write('\n')
	}
	io.stdout.write('\n\n')
}

console.getText( "按回车键继续 ... " )


最新回复 (1)
  • 光庆 2023-8-19
    0 2

    我看到了一只雅蠛蝶

返回