LocalDateTime与String日期互相转换
2017-09-30 10:33
531 查看
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime time = LocalDateTime.now();
String localTime = df.format(time);
LocalDateTime ldt = LocalDateTime.parse("2017-09-28 17:07:05",df);
System.out.println("LocalDateTime转成String类型的时间:"+localTime);
System.out.println("String类型的时间转成LocalDateTime:"+ldt);
控制台结果:
LocalDateTime转成String类型的时间:2017-09-30 10:40:06
String类型的时间转成LocalDateTime:2017-09-28T17:07:05
LocalDateTime time = LocalDateTime.now();
String localTime = df.format(time);
LocalDateTime ldt = LocalDateTime.parse("2017-09-28 17:07:05",df);
System.out.println("LocalDateTime转成String类型的时间:"+localTime);
System.out.println("String类型的时间转成LocalDateTime:"+ldt);
控制台结果:
LocalDateTime转成String类型的时间:2017-09-30 10:40:06
String类型的时间转成LocalDateTime:2017-09-28T17:07:05
相关文章推荐
- 11、Java String类型与Date日期类型互相转换
- C# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)
- String类型与Date日期类型互相转换
- 在java中实现日期类型和字符串类型的转换_所有(Date String Timestamp Datetime)
- java8的LocalDateTime与Date互相转换
- C# 日期和时间的字符串表示形式转换为其等效的DateTime(stringToDateTime)
- C#中使用DateTime.ToString()转换输出日期
- java中 String类型与Date日期类型互相转换
- java中输入的日期打印出星期几,Date互相转换String
- scala LocalDateTime String 转换
- 计算两个日期之间相差几天(Date类型与String类型互相转换)
- spring-boot 接口请求之Date、LocalDate、LocalDateTime日期类型转换处理
- 给定的日期--String类型和Date类型互相转换。
- MFC CString和string的互相转换
- Python中String与时间戳、datetime转换
- string[]与int[] 互相转换
- C# Enum,Int,String的互相转换 枚举转换
- CString 和 string, char * , char[], 以及其他类型之间的互相转换小结
- python中time类型,datetime类型的关系与互相转换
- 自定义日期类型的数据绑定 前台 - 后台 或 后台 - 前台 互相转换