My Input is like this:
20180718140032488266000Z-0600
and the way it should go and persist in database is like this:
21-JUL-18 12.05.25.000000000 AM
Currently I have written code like this :
public static void main(String[] argv) throws ParseException {
// SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSSZ");
String dateInString = "20180718140032488266000Z-0600";
Timestamp ts = formatDate(dateInString);
System.out.println(ts);
}
private static Timestamp formatDate(String dateString) throws ParseException {
// dateString = dateString.replaceAll("Z", "0000");
SimpleDateFormat fmtTimestamp = new SimpleDateFormat("yyyyMMddHHmmssSSS'Z'");
Date dtTimestamp1 = fmtTimestamp.parse(dateString);
Timestamp timestamp = new java.sql.Timestamp(dtTimestamp1.getTime());
return timestamp;
}
I am getting an output in this format: 2018-07-24 05:38:18.0
, my question is how can I get AM/PM also in the output. Please suggest solutions. I will be really grateful.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…