I would like to convert it to a double - the integer
part which is the number of days that have passed
since 12/30/1899, and the fractional part is the fraction
of the 24 hour day that has elapsed. (This is the Delphi
format, and maybe the format for other languages and
systems. But I'll doing the conversion in C/C++).
Has this been solved before? Where should I look?
Thanks much!
--
comp.lang.c.moderated - moderation address: cl...@plethora.net
#define DELPHI_DAYS_1970 (2 + 70*365 + 17)
double DelphiTime(time_t DosTime)
{
return DosTime/86400.0 + DELPHI_DAYS_1970;
}
Dag
"Dave Parker" <inv...@null.com> wrote in message
news:clcm-2004...@plethora.net...
>I need some pointers to handling/converting time
>values. I'm reading a file from a legacy DOS
>application that uses a time_t type. This is a
>typedef for a long. I understand that this is the
>number of seconds since midnight, January 1, 1970.
>I would like to convert it to a double - the integer
>part which is the number of days that have passed
>since 12/30/1899, and the fractional part is the fraction
>of the 24 hour day that has elapsed. (This is the Delphi
>format, and maybe the format for other languages and
>systems. But I'll doing the conversion in C/C++).
>
>Has this been solved before? Where should I look?
time_t t;
double time = t/86400. + 25569.;
Division by 86400 (60*60*24) converts from seconds into days. Addition
of the offset 25569 (70*365 + 17 + 2) converts the base time from
1970-Jan-01 00:00 to 1899-Dec-30 00:00.
There were 70 years between and including 1900 and 1969, treated as
365 days each, plus 17 leap days between and including 1904 and 1968
(1900 was *NOT* a leap year), and 2 extra for Dec 30/31.
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian....@CSi.com (Brian dot Inglis at SystematicSw dot ab dot ca)
fake address use address above to reply
Hint 1: There are 84,600 seconds in a day.
Hint 2: There are 25,569 days from 30-Dec-1899 to 1-Jan-1970. (BTW, are
you sure you want December _30_?)
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
I would recomment you read The standard C Library by Plauger.
As I understaind it time_t is just that. A way to hold a
representation of time. Then only function that then makes sense is
difftime(). Which is the difference between two time_t elements.
Also search the archives here since I have similar questions posted.
Good Luck
George