What is the best way to remove the 'T' character? Any idea guys?
Use a 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));
Which prints...
2015-10-23T03:34:40
2015-10-23 03:34:40
03:34:40 2015-10-23
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 DateTimeFormatter
to format the date/time value to what ever format you want and display that
I need to remove the 'T' to match data in my database.
Opps, missed that part.
In this case, you should be converting your Date/Time values to use java.sql.Timestamp
and using a PreparedStatement
to insert/update them
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…