package com.aaa.day04.api; import com.aaa.utils.MyTool; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.Set; /** * @author :nie6668888 * @date :Created in 2024/11/15 14:22 * @description: * @modified By: * @version: */ public class MyLocalDateTime { public static void main(String[] args) { /* //获取系统最新时间 LocalDateTime now = LocalDateTime.now(); System.out.println(now); //获取当前的时区 ZoneId zoneId = ZoneId.systemDefault(); System.out.println(zoneId); //获取所有的时区 Set<String> zoneIds = ZoneId.getAvailableZoneIds(); for (String id : zoneIds) { System.out.println(id); } //获取今天是当年的第几天 int dayOfYear = now.getDayOfYear(); System.out.println(dayOfYear);*/ //创建一个loacaldatetime类型的数据 /* LocalDateTime localDateTime = LocalDateTime.of(2024,11,14,8,20,15); System.out.println(localDateTime); //使用字符串方式创建localdatetime LocalDateTime localDateTime1 = LocalDateTime.parse("2024-11-14T17:30:45"); System.out.println(localDateTime1); //计算两个时间差 Duration between = Duration.between(localDateTime1, localDateTime); *//* long l = between.toDays() / 365; System.out.println(l);*//* System.out.println(between);*/ //以固定格式输入时间 yyyy-MM-dd HH:mm:ss,DateTimeFormatter //获取一个DateTimeFormatter对象 /* DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime dateTime = LocalDateTime.parse("2024-11-14 17:30:45.345", dtf); System.out.println(dateTime);*/ //使用localdatetime转换成字符串yyyy-MM-dd HH:mm:ss /* LocalDateTime localDateTime = LocalDateTime.now(); DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String format = localDateTime.format(dtf); System.out.println(format);*/ /* LocalDateTime localDateTime = LocalDateTime.now(); String s = MyTool.fromLocalDateTimeToString(localDateTime); System.out.println(s);*/ /* LocalTime time= LocalTime.now(); System.out.println(time);*/ LocalDate date=LocalDate.now(); System.out.println(date); } }标签:常用,示例,localDateTime,System,LocalDateTime,println,now,out From: https://blog.csdn.net/nie6668888/article/details/143798581