package begin;
import java.time.LocalDate;
import java.time.Month;
/**
*
* <p>Title: Calendar01</p>
* <p>Description: </p>
* @author lch
* @date 2020-9-6
*/
public class Calendar01 {
public static void main(String[] args) {
//获得当天的日期
LocalDate date = LocalDate.now() ;
//获得今天是这个月的第几天
int day = date.getDayOfMonth() ;
//获得当前月
int mon = date.getMonth().getValue();
// System.out.println(day);
//获得今天的星期
int wek = date.getDayOfWeek().getValue() ;
// System.out.println(wek);
//打印上日历上方的星期
System.out.println("Mon Tue Web Thu Fri Sat Sun");
//打印出空格
for(int i = 1 ; i< wek ; i++)
{
System.out.print(" ");
}
//把当前月的剩余日期都打印出来
while(date.getMonth().getValue() == mon) {
if (date.getDayOfMonth() == day) {
System.out.printf("%3d ",day);
}
else {
System.out.printf("%3d ",date.getDayOfMonth());
}
//日期增加
date = date.plusDays(1) ;
if(date.getDayOfWeek().getValue() == 1) {
System.out.println();
}
}
}
}
效果图:
Python实现日历
import calendar
yy = int(input("输入年份:"))
mm = int(input("输入月份:"))
# 显示日历
print(calendar.month(yy,mm))