package J20250808.localDateTime; import java.time.LocalDateTime; /** * @author WanJl * @version 1.0 * @title Demo01_LocalDateTime * @description * @create 2025/8/8 */ public class Demo01_LocalDateTimeTest { public static void main(String[] args) { //获取当前系统的时间 LocalDateTime now = LocalDateTime.now(); System.out.println(now); //使用指定年月日时分秒初始化一个LocalDateTime对象 LocalDateTime of = LocalDateTime.of(2000, 2, 22, 22, 22, 22); System.out.println(of); //获取年 int getYear() System.out.println("今年是:"+now.getYear()); //获取月份1-12 int getMonthValue() System.out.println("这个月是:"+now.getMonthValue()); //获取月份中的第几天 1~31 int getDayOfMonth() System.out.printf("今天是本月中的第%d天\n",now.getDayOfMonth()); //获取一年中的第几天 1~366 int getDayOfYear() System.out.printf("今天是今年中的第%d天\n",now.getDayOfYear()); //获取星期 DayOfWeek getDayOfWeek() System.out.println("今天是"+now.getDayOfWeek()); //获取小时 getHour() System.out.println("小时:"+now.getHour()); //获取分钟 getMinute() System.out.println("分钟:"+now.getMinute()); //获取秒 getSecond() System.out.println("秒:"+now.getSecond()); } }