首页 > 编程语言 > 详细

用Java中的LocalDate类编写日历程序,

时间:2020-03-24 22:01:18      阅读:83      评论:0      收藏:0      [点我收藏+]
2020-03-24    17:11:08


package lianxi1;
import  java.time.*;
/**
 2020/03/24
 **/
public class CalenderTest {
    public static void main(String[] args){
        LocalDate date = LocalDate.now();
        int month = date.getMonthValue();      //获取今天的月份
        int today = date.getDayOfMonth();      //获取今天的日期

        date = date.minusDays(today - 1);
        DayOfWeek weekday = date.getDayOfWeek();    
        int value = weekday.getValue();            //  周

        System.out.println("Mon Tue Wed Thu Fri Sat Sun");
        for (int i = 1; i < value;i++)
            System.out.print("    ");
        while(date.getMonthValue() == month)
        {
            System.out.printf("%3d",date.getDayOfMonth());
            if (date.getDayOfMonth() == today)
                System.out.print("*");
            else
                System.out.print(" ");
            date = date.plusDays(1);
            if (date.getDayOfWeek().getValue() == 1)
                System.out.println();
        }
        if (date.getDayOfWeek().getValue() != 1)
            System.out.println();
    }
}

  

用Java中的LocalDate类编写日历程序,

原文:https://www.cnblogs.com/rz123/p/12562085.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!