当前位置:网站首页>Localdatetime and string date conversion

Localdatetime and string date conversion

2022-06-10 11:23:00 andQVQ

LocalDateTime Turn into String

DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime time = LocalDateTime.now();
String localTime = df.format(time);
 be equal to 
String localTime = MyDateUtil.formatDateTimeDefault(time);

System.out.println("LocalDateTime Turn into String Type of time :"+localTime);

result :

LocalDateTime Turn into String Type of time :2017-09-30 10:40:06

String Turn into LocalDateTime

DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime ldt = LocalDateTime.parse("2017-09-28 17:07:05",df);
System.out.println("String The type of time turns into LocalDateTime:"+ldt);

result :

String The type of time turns into LocalDateTime:2017-09-28T17:07:05

原网站

版权声明
本文为[andQVQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101102559895.html