Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java date/timezone odd behavior?  RSS feed

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

we have a webservices application that always takes the input of time in its UTC format as


and here is the code that parse the date into a java util Date object

private static final Pattern PATTERN = Pattern.compile(

Matcher m = PATTERN.matcher(dateString);
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
int hoff = 0, moff = 0, doff = -1;
if ( != null) {
doff ="-") ? 1 : -1;
hoff = doff * ( != null ? Integer.parseInt( : 0);
moff = doff * ( != null ? Integer.parseInt( : 0);
c.set(Calendar.YEAR, Integer.parseInt(;
c.set(Calendar.MONTH, != null ? Integer.parseInt( : 0);
c.set(Calendar.DATE, != null ? Integer.parseInt( : 1);
c.set(Calendar.HOUR_OF_DAY, != null ? Integer.parseInt( + hoff: 0);
c.set(Calendar.MINUTE, != null ? Integer.parseInt( + moff: 0);
c.set(Calendar.SECOND, != null ? Integer.parseInt( : 0);
c.set(Calendar.MILLISECOND, != null ? Integer.parseInt( : 0);
return c.getTime();

Recently an odd thing was observed that as the application first starts, the returned date will be just correctly printed as
Thur Dec 06 00:00:00 EST 2012

since we are in EST timezone. Then after a while, after some execution, even without restart the application, the same date would be printed as
Thur Dec 06 05:00:00 UTC 2012

I have been digging down in the application and I don't see any changes that would reset the default timezone of our application. How could that happen? It has been a week since we started working on this and we are still clueless :-(

Also, is there anyway to make sure the application keeps using the system timezone as that would not be changing?

thanks a lot for any help/hints
Posts: 23273
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gigi, welcome to the Ranch!

We prefer to have only one thread on a topic, it cuts down on the confusion when different people try to answer the different duplicates. So I'll close this one.

For those interested, here's the other thread:, please go there to reply.
Always! Wait. Never. Shut up. Look at this tiny ad.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!