LocalDateTime如何同String进行互相转换呢?
下文笔者讲述LocalDateTime和String之间互相转换的方法及示例分享,如下所示
LocalDateTime同String互相转换的实现思路
借助LocalDateTime.parse方法和DateTimeFormatter方法即可实现互相转换例:LocalDateTime和String互相转换的示例
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime time = LocalDateTime.now(); String localTime = df.format(time); LocalDateTime ldt = LocalDateTime.parse("2023-05-20 22:47:06",df); System.out.println("LocalDateTime转成String类型的时间:"+localTime); System.out.println("String类型的时间转成LocalDateTime:"+ldt);
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。