package com.lty;
import java.time.*;
public class LocalDateTimeDemo {
public static void main(String[] args) {
LocalDateTime time = LocalDateTime.now();
System.out.println(time);
int year = time.getYear();
System.out.println(year);//年
Month month = time.getMonth();
System.out.println(month);//月
int monthValue = time.getMonthValue();
System.out.println(monthValue);//月(数字)
System.out.println("----------");
int dayOfMonth = time.getDayOfMonth();
DayOfWeek dayOfWeek = time.getDayOfWeek();
int dayOfYear = time.getDayOfYear();
System.out.println(dayOfYear);
System.out.println(dayOfMonth);
System.out.println(dayOfWeek);
System.out.println("----------");
int hour = time.getHour();
System.out.println(hour);
int minute = time.getMinute();
System.out.println(minute);
int second = time.getSecond();
System.out.println(second);
int nano = time.getNano();
System.out.println(nano);
System.out.println("------------");
LocalTime time1 = time.toLocalTime();//转时间
System.out.println(time1);
LocalDate date = time.toLocalDate();//转日期
System.out.println(date);
}
}
LocalDateTime的使用
最新推荐文章于 2024-07-22 14:15:06 发布