Different Epoch dates and Number of Days Count

G

gibboda

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
 
E

Eric Sosman

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

gibboda

gibbodawrote On 02/14/07 09:16,:






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.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top