realbasic-nug
[Top] [All Lists]

Re: Java date to RB date

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Java date to RB date
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Sun, 31 Oct 2004 19:26:34 -0600
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <645DE11E-2B9F-11D9-B648-00039346A7A8 at mac dot com>
When you assign the value to the TotalSeconds property, I believe it's going override the day, month and year values you've assigned. I'm surprised the values you are getting are so close together. That's probably just a coincidence. Don't bother setting the day, month and year properties. Instead, assign to TotalSeconds the number of seconds between January 1st, 1904 (the base data for REALbasic dates) and January 1st, 1970 (the base Java date) plus the milliseconds you parsed converted to seconds.

That should do it.

On Oct 31, 2004, at 6:45 PM, Steve Roy wrote:

Hm, here's a fun one. I'm parsing a text file created by another program written in Java. The date is written as the number of milliseconds since January 1, 1970, 0:00:00, as the java.util.Date class defines it. When I convert this into a REALbasic date, the result doesn't match. Here's what I do:

dim millis as String = ... // Parsed text for the Java date
dte = new Date()
dte.Day = 1
dte.Month = 1
dte.Year = 1970
dte.Hour = 0
dte.Minute = 0
dte.Second = 0
dte.TotalSeconds = dte.TotalSeconds + Val(millis) / 1000

When displayed in my RB app, this thusly built date shows up as
        10/25/04 12:49 AM
whereas it shows up as
        10/24/04 8:49:26 PM
in the original Java app, which means I'm 17 hours off.

I'm trying to see what could account for this difference. Do you see something I missed? I thought that by creating a new date object and making it correspond to the reference Java date (1/1/1970 0:00:00), that everything would be peachy but it's not. Is there any other way I could do this?

--
Geoff Perlman
President and CEO
REAL Software, Inc.

REAL World 2005 - The REALbasic User Conference
March 23rd - 25th, 2005, Austin, Texas
<http://www.realsoftware.com/realworld>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>