What is the best way to remove the 'T' character? Any ideas guys?
Use DateTimeFormatter to format the LocalDateTime value the way you want ...
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));
What prints ...
2015-10-23T03:34:40 2015-10-23 03:34:40 03:34:40 2015-10-23
Remember that date and time objects are just a container for the amount of time elapsed from a fixed point in time (for example, in the Unix era), they do not have their own / custom format, they tend to use the current locale format.
Instead, when you want to represent a date / time value, you should first use DateTimeFormatter to format the date / time value in whatever format you want, and display that
I need to remove the "T" to match the data in my database.
Opps, skipped this part.
In this case, you must convert your Date / Time values ββto use java.sql.Timestamp and use PreparedStatement to insert / update them
source share