问题描述
如何在我的localDate中删除T?
我需要删除'T'来匹配数据库中的数据。
这是我的代码
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(yyyy-MM-dd'T HH:mm:ss,Locale.US);
String strLocalDate = patientDiagnosisByDoctor.getDiagnosisDateTime()。toLocalDateTime()。toString();
LocalDateTime localDate = LocalDateTime.parse(strLocalDate,formatter);
System.out.println(localDate);
我得到这个输出:
2015-10-23T03:34:40
什么是最好的删除T字符的方式?任何想法家伙?
使用 DateTimeFormatter
格式化 LocalDateTime
你想要的方式...
DateTimeFormatter formatter = DateTimeFormatter.ofPattern (yyyy-MM-dd'T'HH:mm:ss,Locale.US);
String strLocalDate =2015-10-23T03:34:40;
LocalDateTime localDate = LocalDateTime.parse(strLocalDate,formatter);
System.out.println(localDate);
System.out.println(DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss)。format(localDate));
System.out.println(DateTimeFormatter.ofPattern(HH:mm:ss yyyy-MM-dd).format(localDate));
哪些打印...
2015-10-23T03:34:40
2015-10-23 03:34:40
03:34:40 2015-10-23
记住,日期/时间对象只是一个从一个固定的时间点过去的时间量的容器(如Unix epoch),它们没有自己的内部/可配置格式,它们倾向于使用当前的区域设置格式。
相反,当您要呈现日期/时间值,您应该首先使用 DateTimeFormatter
将日期/时间值格式化为您想要的格式,并显示
在这种情况下,您应该将您的日期/时间值转换为使用 c $ c>并使用 How to remove T in my localDate? I need to remove the 'T' to match data in my database. This is my code I got this output: What is the best way to remove the 'T' character? Any idea guys? Use a Which prints... Remember, date/time objects are just a container for amount of time which has passed since a fixed point in time (like the Unix epoch), they don't have a internal/configurable format of their own, they tend to use the current locale's format. Instead, when you want to present the date/time value, you should first use a Opps, missed that part. In this case, you should be converting your Date/Time values to use 这篇关于LocalDate - 如何在LocalDate中删除字符“T”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! java.sql.Timestamp $($ / $)
PreparedStatement
插入/更新他们DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
String strLocalDate = patientDiagnosisByDoctor.getDiagnosisDateTime().toLocalDateTime().toString();
LocalDateTime localDate = LocalDateTime.parse(strLocalDate, formatter);
System.out.println(localDate);
2015-10-23T03:34:40
DateTimeFormatter
to format the value of LocalDateTime
the way you want it...DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
String strLocalDate = "2015-10-23T03:34:40";
LocalDateTime localDate = LocalDateTime.parse(strLocalDate, formatter);
System.out.println(localDate);
System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(localDate));
System.out.println(DateTimeFormatter.ofPattern("HH:mm:ss yyyy-MM-dd ").format(localDate));
2015-10-23T03:34:40
2015-10-23 03:34:40
03:34:40 2015-10-23
DateTimeFormatter
to format the date/time value to what ever format you want and display thatjava.sql.Timestamp
and using a PreparedStatement
to insert/update them