After calling toDate, the actual instant in time that it represents is 
preserved. What you are seeing is just a different interpretation of how 
it should be presented. If you construct a DateTime again from the Date, 
you should see that it is the same as it was before. The underlying 
instant in both DateTime and Date is the number of milliseconds elapsed 
from 1970-01-01T00:00.00.000Z. The values returned by 
DateTime.getMillis() and Date.getTime() will be the same.

Andreas Guther wrote:
>
> Brian,
>
> Thank you for your explanation. I will try to solve the problem using 
> the GJChronology.
>
> In general I feel that my expectation is mislead by providing a toDate 
> method that returns a java.util.Date object that contains a different 
> date than the DateTime object.
>
> I could also not find a hint on the problematic in the Java code 
> (JavaDocs). My expectation is that a method toDate returning a 
> java.util.Date should be able to return the correct object. If Joday 
> Time knows about the different calendars, why not internally adjust 
> and correct the difference rather than move the burden to the user. Or 
> not providing a toDate at all.
>
> Andreas
>
> *From:* Brian O'Neill [mailto:[EMAIL PROTECTED]
> *Sent:* Monday, November 10, 2008 5:33 PM
> *To:* Discussion of the Joda project
> *Subject:* Re: [Joda-interest] Problem with DateTime toDate - 
> java.util.Date returns different date
>
> Joda-Time by default uses an ISO chronology, which is a proleptic 
> gregorian calendar. Java's Date class uses a gregorian/julian calendar 
> which has a gap of several days to account for the error between the 
> two. If you want the two representations to be the same, you need to 
> use Joda-Time's GJChronology.
>
> Other differences are caused by how the time zone rules are 
> implemented. Joda-Time strictly follows the tz database rules, which 
> is why you see differences before 1884.
>
> If you want to support historical datetimes in a consistent fashion, 
> the easiest thing is to not switch between Joda-Time and Java Date.
>
> On Mon, Nov 10, 2008 at 4:36 PM, Andreas Guther 
> <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> Hi,
>
> I noticed a converting problem from DateTime to java.util.Date. Dates 
> in the past seem to be off by one or more days, depending on how far 
> those dates are in the past. My observation is, that dates until 1884 
> are fine, but before are starting to be off by one day. Is there 
> something I have to configure. It is hard to believe that this is a bug.
>
> public static void main(String[] args) {
>
> DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd/yyyy");
>
> DateTime dateTime = fmt.parseDateTime("10/11/1492");
>
> System.out.println(dateTime);
>
> // prints 1492-10-11T00:00:00.000-07:52:58 – AS EXPECTED
>
> System.out.println(dateTime.toDate());
>
> // prints Mon Oct 01 23:52:58 PST 1492 – MONTH OK, BUT DAY WAY OFF!!!!
>
> }
>
> We are currently using joda-time 1.5.2. <http://1.5.2.>
>
> Andreas
>
>
> -------------------------------------------------------------------------
> 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=/ 
> <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
> _______________________________________________
> Joda-interest mailing list
> Joda-interest@lists.sourceforge.net 
> <mailto:Joda-interest@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> 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
>   

-------------------------------------------------------------------------
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