Different Epoch dates and Number of Days Count

Discussion in 'Java' started by gibboda, Feb 14, 2007.

  1. gibboda

    gibboda Guest

    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
    gibboda, Feb 14, 2007
    #1
    1. Advertising

  2. gibboda

    Eric Sosman Guest

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


    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.

    --
    Eric Sosman, Feb 14, 2007
    #2
    1. Advertising

  3. gibboda

    gibboda Guest

    On Feb 14, 11:02 am, Eric Sosman <> wrote:
    > gibbodawrote 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
    > > 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.

    >
    > 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.
    >
    > --
    > - Hide quoted text -
    >
    > - 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.
    gibboda, Feb 16, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Henry
    Replies:
    6
    Views:
    16,157
    Brian Henry
    Nov 19, 2003
  2. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    845
    Rob Schieber
    Sep 30, 2005
  3. days since epoch

    , Feb 17, 2006, in forum: Python
    Replies:
    3
    Views:
    561
    Marius Gedminas
    Feb 17, 2006
  4. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    180
    Mark Schupp
    Aug 9, 2004
  5. Li Chen
    Replies:
    2
    Views:
    107
    Li Chen
    Mar 4, 2010
Loading...

Share This Page