本程序遵循国际惯例,与我们日常生活中的使用日历习惯相似,仅供参考。
运行截图:
程序源代码:
package Joey1;
import java.time.*;
import java.util.*;
public class j {
public static void main(String args[])
{
LocalDate date = LocalDate.now();
int year = date.getYear();//The year is...
int mouth = date.getMonthValue();//The mouth is...
int today = date.getDayOfMonth();//The today is...
System.out.println(mouth+" "+year);
date = date.minusDays(today-1);//Set to start of mouth
DayOfWeek weekday = date.getDayOfWeek();
int value = weekday.getValue();//1 = Monday...
System.out.println("SUN MON TUE WED THU FRI SAT");
for(int i = 0;i < value&&value < 7;i++)
System.out.print(" ");
while(date.getMonthValue() == mouth)
{
System.out.printf("%3d",date.getDayOfMonth());
if(date.getDayOfMonth() == today)
System.out.print("*");//The date of the day is marked.
else
System.out.print(" ");
date = date.plusDays(1);//next day
if(date.getDayOfWeek().getValue() == 7)
System.out.println();//Line feed printing
}
if(date.getDayOfWeek().getValue() == 7)
System.out.println();//Line feed printing
}
}