wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date and Daylight Savings Time" Watch "Date and Daylight Savings Time" New topic
Author

Date and Daylight Savings Time

Dominique Ramoney
Greenhorn

Joined: Aug 11, 2004
Posts: 25
Hi

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.

Thanks
Dominique
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
Greenhorn

Joined: Aug 11, 2004
Posts: 25
Hi

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
Greenhorn

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();
dtz.setStartRule(0,0,0,0);
dtz.setEndRule(0,0,0,0);
TimeZone.setDefault(dtz);

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: http://aspose.com/file-tools
 
subject: Date and Daylight Savings Time
 
Similar Threads
Converting a date object from GMT to EST
Does Java TimeZone takes care of daylight savings?
How to get java Date with Daylight savings
Calendar Method
Date and Daylight Savings Time