LocalDate类
Posted joey777210
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LocalDate类相关的知识,希望对你有一定的参考价值。
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("* "); }else { System.out.print(" "); } date = date.plusDays(1); if(date.getDayOfWeek().getValue() == 1) { System.out.println(); } } if(date.getDayOfWeek().getValue() != 1) { System.out.println(); } } }
以上是关于LocalDate类的主要内容,如果未能解决你的问题,请参考以下文章