When using SimpleDateFormatter.format in the following code, hours between 12:00 and 12:59 are shown as 00:00 to 00:59 in startDateText TextView, while since 13:00 on they are correctly shown as 13:xx, 14:xx up to 23:59.
---- Refactored code as requested When the string in the dtold.parse(...) is an the in example the output hour is 00:00, when it is "13:00" it is correctly "13:00"
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
SimpleDateFormat dtnew = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
SimpleDateFormat dtold = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Calendar cal = Calendar.getInstance();
cal.setTime(dtold.parse("2017-03-12 12:33:33"));
cal.add(Calendar.SECOND, 10);
System.out.println(dtnew.format(cal.getTime()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}