Monday, January 20, 2020

print date in MM/dd/yyyy hh:mm:ss a

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

SimpleDateFormat formatter, FORMATTER;
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
String oldDate = "2008-03-14T11:53:31.200+05:00";
Date date = formatter.parse(oldDate.substring(0, 26) + oldDate.substring(27, 29));
FORMATTER = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
System.out.println("OldDate-->"+oldDate);
log.info("NewDate-->"+FORMATTER.format(date));
vars.put("myvar", FORMATTER.format(date)); 

No comments: