Hi all

I'm having trouble working out how to set a date to midnight. It seems
that some timezone issues are causing me problems when I create
DateTime variable, and I'm a bit stumped regarding what I am doing
wrong.

When I run my class DateTes, I get the following output

Timezone is 
sun.util.calendar.ZoneInfo[id="Australia/Sydney",offset=36000000,dstSavings=3600000,useDaylight=true,transitions=142,lastRule=java.util.SimpleTimeZone[id=Australia/Sydney,offset=36000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=9,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=1,endMode=3,endMonth=3,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=1]]

date is Mon Oct 20 02:00:00 EST 2008
dt is 2008-10-20T01:00:00.000+10:00
dt toDate Mon Oct 20 02:00:00 EST 2008
midnightDateTime is 2008-10-20T00:00:00.000+10:00
midnightDateTime toDate is Mon Oct 20 01:00:00 EST 2008
midnightDate is Mon Oct 20 01:00:00 EST 2008

Basically I want to change the dat Mon Oct 20 02:00:00 EST 2008 to Mon
Oct 20 00:00:00 EST 2008

When I create the DateTime variable though, it looks like some funky
timezone change occurs and it stores the date using a different
timezone? and a time of 1:00, so when I set the time to 0:00 it only
subtracts one hour. When I convert the DateTime back into a date i End
up with Mon Oct 20 01:00:00 EST 2008

Can anyone help me out? How can I make jodatime preserve timezone data
so the DateTime variable has the same hour value (ie 2 oclock) as the
original java.util.Date variable?

Thanks

My class:

import java.util.Date;
import java.util.TimeZone;

import org.joda.time.DateTime;

public class DateTest {

    public static void main(String args[]) {

        System.out.println("Timezone is " + TimeZone.getDefault());
        // 20 Oct 2008 2:00:00
        Date date = new Date(108, 9, 20, 2, 0, 0);
        System.out.println("date is " + date.toString());

        DateTime dt = new DateTime(date.getTime());
        System.out.println("dt is " + dt.toString());
        System.out.println("dt toDate " + dt.toDate().toString());

        DateTime midnightDateTime = dt.withTime(0, 0, 0, 0);
        System.out.println("midnightDateTime is " + 
midnightDateTime.toString());
        System.out.println("midnightDateTime toDate is " +
midnightDateTime.toDate().toString());

        Date midnightDate = midnightDateTime.toDate();
        System.out.println("midnightDate is " + midnightDate.toString());
    }
}

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to