JAVA中LocalDate类日历表的建立(eclipse 实例)

  本程序遵循国际惯例,与我们日常生活中的使用日历习惯相似,仅供参考。

   运行截图:
JAVA中LocalDate类日历表的建立(eclipse 实例)_第1张图片

 程序源代码:

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
    }
}
 

你可能感兴趣的:(JAVA,java,eclipse,开发语言,程序人生,算法)