how can i convert a mm/dd/yyyy uu:mm:ss to a time_t ?

how can i convert a mm/dd/yyyy uu:mm:ss to a time_t ?

Post by Joha » Fri, 13 Nov 1998 04:00:00



Let us say that i want to store a record with data in a file and one of the
fields in this record is a time_t (number of seconds since 1/1/1970) and  I
want to search for this time_t in the file.

The system works in GMT, and when i read the unix manuals, one can make a TZ
string and from this string the system can calculate the normal local time,
and the local time when daylight savings time is in effect. The system
administrator has to change this string anually.

With mktime one can make a time_t from a struct. When I fill in this struct
the local DD/MM/YYYY UU:MM:SS, does this function converts this to the exact
GMT? And how works this for the past years, since there is only one active
TZ string.

I want to search for the date and time in a file. Is it possible with a
time_t field, or do i have to make a string YYYYMMDDUUMMSS. In the first
case I only need 4 bytes, in the latter 15.

 
 
 

how can i convert a mm/dd/yyyy uu:mm:ss to a time_t ?

Post by Allan Meidlei » Sat, 14 Nov 1998 04:00:00


Quote:>With mktime one can make a time_t from a struct. When I fill in this struct
>the local DD/MM/YYYY UU:MM:SS, does this function converts this to the
exact
>GMT? And how works this for the past years, since there is only one active
>TZ string.

After using mktime to populate the struct, you can use the strftime()
function to generate a character string in a variety of formats.  There are
just over 20 ( I think ) formats ranging from day-of-month as decimal to
Julian date to week-of-year.  The beauty of this function is that it is easy
to generate any combination of dates and put it all into one string.  Just
look it up in your C manual or on unix, read the man page.  This is what it
looks like, quick and dirty:

#include <time.h>
size_t strftime(char *str, size_t maxsize, const char *fmt, const struct tm
*time);

I hope this helps.

Quote:>I want to search for the date and time in a file. Is it possible with a
>time_t field, or do i have to make a string YYYYMMDDUUMMSS. In the first
>case I only need 4 bytes, in the latter 15.