I am writing a program that has a header where the current time is displayed. I want to allow the user to modify date/time settings. But after the user modifications I cannot get the calendar to stay up-to-date. It always shows the value entered by the user. For example:
Calendar cal = Calendar.getInstance();
System.out.println(cal.getTime());
cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(cal.getTime());
Let's say the first output is
Mon Feb 18 11:33:07 CET 2013
What I want here is to get after 2 seconds a second output
Mon Sep 18 11:33:09 CET 2013 // Month = Sep and Seconds = 09
What I get instead is
Mon Sep 18 11:33:07 CET 2013 // Month = Sep, seconds don't change, still 07!!
If I add cal = Calendar.getInstance();
before the second output, I'll get
Mon Feb 18 11:33:09 CET 2013 // Seconds = 09, month doesn't change, still Feb!!
I think there must be an easy and obvious implementation that I cannot find.
UPDATE: I cannot use DateFormat on the embedded system I am working on.