I have a SQL query which returns one column value-2020-07-01 03:43:30.0(yyyy-mm-dd hh:mm:ss.ms).I want to convert this into 'mm/dd/yyyy hh24:mi' format using Java code.How to do this with Java.
You can use two different DateTimeFormatter
s:
DateTimeFormatter parseFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
DateTimeFormatter resultFormat = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm");
Where parseFormat
is used for parsing and resultFormat
is used to produce the String
from the parsed date:
LocalDateTime ldt = LocalDateTime.parse("2020-07-01 03:43:30.0", parseFormat);
String result = ldt.format(resultFormat);
System.out.println(result);
Prints:
07/01/2020 03:43
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.