Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Time Handling

1 view
Skip to first unread message

Dave Parker

unread,
Aug 14, 2004, 6:32:38 AM8/14/04
to
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?

Thanks much!
--
comp.lang.c.moderated - moderation address: cl...@plethora.net

Dag Viken

unread,
Aug 17, 2004, 11:25:35 PM8/17/04
to
You just have to figure out the number of days from 12/30/1899 to
01/01/1970. There are 2 days in 1899, then 70 years plus the leap days.
Remember year 1900 is not a leap year, so there are 17 leap days. The
following function should work:

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

Brian Inglis

unread,
Aug 17, 2004, 11:25:39 PM8/17/04
to
On 14 Aug 2004 10:32:38 GMT in comp.lang.c.moderated, "Dave Parker"
<inv...@null.com> wrote:

>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

Kenneth Brody

unread,
Aug 17, 2004, 11:25:52 PM8/17/04
to
Dave Parker wrote:
>
> 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?

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

George

unread,
Aug 17, 2004, 11:31:53 PM8/17/04
to
"Dave Parker" <inv...@null.com> wrote in message news:<clcm-2004...@plethora.net>...

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

0 new messages