Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Different Epoch dates and Number of Days Count

Thread view: 
gibboda - 14 Feb 2007 14:16 GMT
I am trying to determine what is the best way to calculate a date
using Calendar or Date java class.  Searched the user group but did
not find anything to help with dealing with different epoch dates
between two different systems.  What I have is a system where I pull
from to put into different database but one issue arose doing this.
This date I pull of this system does not come in MM/DD/YY format but
in a integer number of days from an epoch of December 31, 1967.  The
epoch is not standard epoch date that I have found on any of the known
operating system and it counts in number of days from epoch. Therefore
I cannot just pull the epoch date of the new system which does not
match with the new system.  Also the new system counts in milliseconds
not days when counting from epoch date. Because of this unusually
date, I have not found a simple way to convert this back into the
proper date and it does not appear that the Calendar or Date class
takes in an account of having a different epoch date than the system
which the code is running on.  Any suggestion where I should begin
looking if the Java Calendar Class is not the appropiate course of
action.

Thank you,
gibboda
Eric Sosman - 14 Feb 2007 16:02 GMT
gibboda wrote On 02/14/07 09:16,:
> I am trying to determine what is the best way to calculate a date
> using Calendar or Date java class.  Searched the user group but did
[quoted text clipped - 14 lines]
> looking if the Java Calendar Class is not the appropiate course of
> action.

    static Date dateFromDayCount(int daysSinceEpoch) {
       Calendar when = new GregorianCalendar(
           1967, Calendar.DECEMBER, 31);
       when.add(Calendar.DAY_OF_YEAR, daysSinceEpoch);
       return when.getTime();
    }

   Depending on exactly what you mean by "days from an epoch
of ...," you might need to start the Calendar from 1-Jan-1968
instead of from 31-Dec-1967.  Find out what "zero days since
the epoch" is supposed to mean, and initialize the Calendar
to that date.

   If the "epoch" is defined in terms of a particular time
zone (e.g., GMT or UTC), you should set up the Calendar to
use that zone.  The code above uses the default local time
zone, meaning that the returned Date depends on the locale
as well as on the count of elapsed days.

Signature

Eric.Sosman@sun.com

gibboda - 16 Feb 2007 14:37 GMT
> gibbodawrote On 02/14/07 09:16,:
>
[quoted text clipped - 40 lines]
>
> - Show quoted text -

Thank you. I will try this out and I will keep in mind the zero day
question. The challenge I am faced with this database is I am using
the tool recommended by the company to pull data out, as I mention ran
into one little problem.  The tool pulls the exact data from this
particular date field as number of days.  I determine that the screens
this system uses converts the number of days into human readable dates
when viewing.  It was a challenged to find out the exact epoch date
since there is no exact documenation on that date because I know most
systems have an epoch of Janaury 1, 1970 date but when I was trying to
calculate the date, I keep being off by 3 years and 1 day once I
determined it was not milliseconds but days.  Now thinking about what
you said about zero date, I just tested a query run to pull only those
with January 1, 1968 which gave me the date to be 1.  And December 31,
1967 gave me the date to be zero.  Again thank you.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.