File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Date and Daylight Savings Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date and Daylight Savings Time" Watch "Date and Daylight Savings Time" New topic

Date and Daylight Savings Time

Dominique Ramoney

Joined: Aug 11, 2004
Posts: 25

The time I get from the Date method is 1 hour ahead of the time set on my sun box. I am asumming this might have something to do with daylight savings. Does anyone know how I might fix this?

I would have imagined that java Date will pick up system time but this doesn't seem to be the case.

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look into creating a custom TimeZone that doesn't recognize daylight savings time and setting it onto your dates. Haven't done this personally, but somebody over the wall said they did it. Let us know how it works out!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dominique Ramoney

Joined: Aug 11, 2004
Posts: 25

I'm still not getting anywhere with this;
I have tho discovered where the problem lies.
Here is the outpur from a calendar instance;

Calendar = java.util.GregorianCalendar[time=1094178292576,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=java.util.SimpleTimeZone[id=Australia/Sydney,offset=36000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=7,startDay=-1,startDayOfWeek=1,startTime=7200000,endMode=2,endMonth=2,endDay=-1,endDayOfWeek=1,endTime=10800000],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2004,MONTH=8,WEEK_OF_YEAR=36,WEEK_OF_MONTH=1,DAY_OF_MONTH=3,DAY_OF_YEAR=247,DAY_OF_WEEK=6,DAY_OF_W EEK_IN_MONTH=1,AM_PM=1,HOUR=1,HOUR_OF_DAY=13,MINUTE=24,SECOND=52,MILLISECOND=576,ZONE_OFFSET=36000000,DST_OFFSET=3600000]

The problem is startMonth=7, it should be 10.

I cannot find how to change this.
Help Please!!!

Dominique Ramoney

Joined: Aug 11, 2004
Posts: 25
Happy, happy, joy, joy!!

I have found a workable solution!

For anyone who comes across this problem, just put this in your main;

SimpleTimeZone dtz = (SimpleTimeZone) TimeZone.getDefault();

This just gets rid of the daylight saving setting, of course the real solution would be to fix the daylight saving setting but I need to at least have one win today.

Also this requires you to;
import java.util.TimeZone;
import java.util.SimpleTimeZone;

I agree. Here's the link:
subject: Date and Daylight Savings Time
jQuery in Action, 3rd edition