Need to convert the time to a specified format but getting a wrong result.Please help
DateFormat readFormat = new SimpleDateFormat( "yyyy-MM-dd hh:mm:ss.sss");
DateFormat writeFormat = new SimpleDateFormat( "hh:mm aa"); //Expecting like 05:00
String from = "2018-02-05 17:00:52.503";
String t0 = "2018-02-05 17:00:55.372";
Date date = null; //IST
Date date2=null;
try {
date = readFormat.parse(from);
date2 =readFormat.parse(to);
} catch (ParseException e) {
e.printStackTrace();
}
if (date != null) {
from = writeFormat.format(date); //Expecting a result of 05.00 pm
to = writeFormat.format(date2); //Expecting a result of 05:00 pm
}
List item## Need out put like this ##
/*But getting an output as:
from= "05:08 pm" instead of 05:00 pm to = "05:06 pm" instead of 05:00 pm
*/