码迷,mamicode.com
首页 > 其他好文 > 详细

LocalDate类

时间:2019-10-28 20:57:42      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:定时   day   for   span   main   port   不同   demo   oca   

LocalDate类与Date类不同。Date类是距离一个固定时间点的毫秒数(UTC 1970.1.1 00:00:00)

Date类表示时间点,LocalDate类用来表示日历表示法。

import java.time.DayOfWeek;
import java.time.LocalDate;

public class Demo3_3_2 {

    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();
        System.out.println(weekday);
        int weekdayv = weekday.getValue();
        System.out.println("Mon    Tue    Wed    Thu    Fri    Sat    Sun");
        for(int i = 1;i<weekdayv;i++) {
            System.out.print("    ");
        }
        
        while(date.getMonthValue() == month) {
            System.out.printf("%3d",date.getDayOfMonth());
            if(date.getDayOfMonth() == today) {
                System.out.print("*\t");
            }else {
                System.out.print("\t");
            }
            date = date.plusDays(1);
            if(date.getDayOfWeek().getValue() == 1) {
                System.out.println();
            }
        }
        if(date.getDayOfWeek().getValue() != 1) {
            System.out.println();
        }
    }
}

 

LocalDate类

标签:定时   day   for   span   main   port   不同   demo   oca   

原文地址:https://www.cnblogs.com/Joey777210/p/11755259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!