首页 > 其他分享 >JDK8之后新增的时间-LocalDate、LocalTime、LocalDateTime、ZoneId、ZoneDateTime

JDK8之后新增的时间-LocalDate、LocalTime、LocalDateTime、ZoneId、ZoneDateTime

时间:2023-10-11 18:33:21浏览次数:32  
标签:LocalDateTime ZoneId JDK8 本地 ldt LocalDate ZoneDateTime LocalTime

LocalDate:代表本地日期(年、月、日、星期)

LocalTime:代表本地时间(时、分、秒、纳秒)

LocalDateTime:代表本地日期、时间(年、月、日、星期、时、分、秒、纳秒)

(其三者都可以调用now()方法,且其对象内容不一样)

LocalDate:

 

 (获取的本地对象是一个不可变对象)

 (注意:修改之后是创建了一个新的对象,原来的对象并不改变)

输出结果为:

2099-09-15

2022-09-15

其他方法:

 (第五个是of方法)

 其余两个与此相似

注意:LocalDateTime可以分成LocalDate和LocalTime

LocalDate ld = ldt.toLocalDate();
LocalTime lt = ldt.toLocalTime();
LocalDateTine ldt = LocalDateTime(ld.lt);

 

Zoneld:代表时区Id

ZoneDateTime:带时区的时间

代码示例:

 可以使用和LocalDate、Time等的方法(with、plus...)

 

标签:LocalDateTime,ZoneId,JDK8,本地,ldt,LocalDate,ZoneDateTime,LocalTime
From: https://www.cnblogs.com/18191xq/p/17756874.html

相关文章

  • 日期格式转换异常:Java 8 date/time type `java.time.LocalDateTime` not supported by
    异常信息:"unexpectederror:Typedefinitionerror:[simpletype,classjava.time.LocalDateTime];nestedexceptioniscom.fasterxml.jackson.databind.exc.InvalidDefinitionException:Java8date/timetype`java.time.LocalDateTime`notsupportedbydefault:......
  • Date与LocalDateTime转换
    在Java中,可以使用java.util.Date和java.time.LocalDateTime类来表示日期和时间。如果需要将Date转换为LocalDateTime,可以使用toInstant()方法将Date转换为Instant,然后再使用atZone()方法将其转换为ZoneId,最后使用toLocalDateTime()方法将其转换为LocalDateTime。示例如下:Datedat......
  • Java-JDK8的下载安装及环境变量配置
    JDK下载网址:JavaDownloads|Oracle(现在需要注册登陆后才可以下载JDK安装包)——有安装包最好!!!进入网址找到Java8==>选择windows视窗==>选择X64,(X64为64位系统,X86为32为系统)。一、下载JDK安装包。   1.双击打开安装包,选择“下一步”。2.选择要安装的目录和组......
  • Localdatetime 8 全局配置
    @ConfigurationpublicclassLocalDateTimeSerializerConfig{privatestaticfinalDateTimeFormatterDATE_TIME_FORMATTER=DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss");privatestaticfinalDateTimeFormatterDATE_FORMATTER=DateTimeFor......
  • 通用解决LocalDateTime转为字符串后中间含“T”
    importcom.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;importorg.springframework.beans.factory.annotation.Value;importorg.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;importorg.springframework.co......
  • jdk8中的ConcurrentHashMap原理和源码解读
    HashMap本身是线程不安全的,所以jdk提供了ConcurrentHashMap,这一篇来看下jdk8中的实现一、基本原理在jdk7中采用了Segment分段锁的思想来实现,在jdk8中不再采用分段锁的思想,jdk8中的ConcurrentHashMap和HashMap一样,都只有一层Entry数组来实现,那么它是怎么保证线程安全呢,我们通......
  • jdk8 流式开发案例
    ListtempList=depts.stream().map(SysDept::getDeptId).collect(Collectors.toList());解释每个方法并转化为常用java代码这段代码使用了Java8中的StreamAPI,对一个名为depts的列表进行操作。下面是对每个方法的解释,并给出相应的常用Java代码示例:1、depts.stream():将......
  • mybatis plus生成的日期时间格式LocalDateTime与String的相互转换
    mybatisplus生成的日期时间格式为LocalDateTime LocalDateTime转为String:将现在的时间转StringStringnowDate=LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-ddHH:mm:ss"))  将指定的String日期转DatetimeLocalDateTimeldatetime=Lo......
  • Java:JSR 310日期时间体系LocalDateTime、OffsetDateTime、ZonedDateTime
    JSR310日期时间体系:LocalDateTime:本地日期时间OffsetDateTime:带偏移量的日期时间ZonedDateTime:带时区的日期时间(目录)日期时间包importjava.time.LocalDateTime;importjava.time.OffsetDateTime;importjava.time.ZonedDateTime;importjava.time.format.DateTimeF......
  • java8 新特性之日期时间处理 LocatDate、LocalTime、LocalDateTime、ZonedDateTime、D
    一、LocalDate、LocalTime、LocalDateTime和常用API1、LocalDatepublicvoidtest01(){//1.创建指定的日期LocalDatedate1=LocalDate.of(2021,05,06);System.out.println("date1="+date1);//2.得到当前的日期LocalDate......