Problem with system time in java

Hi all,

I'm trying to use the following code to get the current system time:

SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMddHHmm");

sdf.setTimeZone(new SimpleTimeZone(0,"GMT"));

qty.setLastmod(sdf.format(new Date()));

System.out.println("LAST MODIFIED DATE:"+qty.getLastmod());

[

But when the system time is 12:26 am. It returns it as 0526. The full format is 200701080526 for yyyyMMDDhhmm when it should be 200701080026. Can anyone please help whats wrong?

Thanks in advance!!!

[716 byte] By [j_raya] at [2007-11-26 14:29:10]
# 1
Your println is using the default toString of a Date (assuming qty.getLastmod() returns a Date).You need to format it with the SimpleDateFormat:System.out.println("LAST MODIFIED DATE:"+sdf.format(qty.getLastmod()));
doremifasollatidoa at 2007-7-8 2:23:25 > top of Java-index,Java Essentials,Java Programming...
# 2
Are you actually in the GMT time zone?
paulcwa at 2007-7-8 2:23:26 > top of Java-index,Java Essentials,Java Programming...
# 3
Yes, I'm using GMT timezone.
j_raya at 2007-7-8 2:23:26 > top of Java-index,Java Essentials,Java Programming...
# 4

> Yes, I'm using GMT timezone.

"using" and "in" are two different things. What is your OS clock set to be in? The hour and minute 0526 is exactly what would be returned at 12:26am if said executing computer was in the eastern standard time zone. ( OS clock instructed that it is in EST )

SpinozaQa at 2007-7-8 2:23:26 > top of Java-index,Java Essentials,Java Programming...
# 5
Let's ask that question in a different way:Are you in England?Or Ireland, I guess. Maybe Iceland, or the west coast of France? I haven't memorized time zone maps.Message was edited by: paulcw
paulcwa at 2007-7-8 2:23:26 > top of Java-index,Java Essentials,Java Programming...
# 6

Or perhaps: what does this code output?

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");

sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));

Date d = new Date();

String s = sdf.format(d);

System.out.println(d);

System.out.println(s);

DrLaszloJamfa at 2007-7-8 2:23:26 > top of Java-index,Java Essentials,Java Programming...
# 7

Sorry if I didnt answer your question right. You are correct. I'm in the EST so it is subtracting 5 from GMT.

But my actual problem is different. At midnight 12am/after 23:59, the system shows the time as 24:00 instead of 00:00. And from here keeps on adding 24:01,24:02,24:03,........etc until 1:00am. How do I correct this to 00:00.

Thanks for your help!

j_raya at 2007-7-8 2:23:26 > top of Java-index,Java Essentials,Java Programming...
# 8
Hmmm... so what you posted wasn't your actual problem... Could you post some code that actually demonstrates your actual problem?
DrLaszloJamfa at 2007-7-8 2:23:26 > top of Java-index,Java Essentials,Java Programming...