From: tony@ermintrude.sunquest.com (Tony Jones)
Subject: Re: Retrieving the day of week
Date: 1996/04/09 [thread overview]
Message-ID: <4kermh$2f7@odin.sunquest.com> (raw)
In-Reply-To: 31629fa4.0@news.planet.ch
rossier@nagra-kudelski.ch wrote:
: How can we retrieve the day of week according to a date which does not
: contain explicitely the day (for example : 13 Jan 1996, 15:30) in C
<snip>
: -> The strptime function does not update the wday field in the
: structure tm.
From strptime(3) (OSF/1 3.0)
The strptime() function modifies only the fields in
the tm structure that have corresponding conversion specifications in the
format.
Given this, I'd suggest using mktime/localtime to convert the struct tm to
epoch time and back (maybe there is a better way anyone?)
Two assumptions jump out here:
1) that you have zero'd your struct tm before calling strptime.
2) that your format to strptime fills in enough fields for the call to
mktime to be meaningful.
How portable this approach is, is open to debate.
tony
#include <stdio.h>
#include <time.h>
main()
{
struct tm tm;
time_t t;
bzero(&tm, sizeof(tm));
if (strptime("9 4 1999 10:01:59", "%d %m %Y %T", &tm) == NULL){
fprintf(stderr,"strptime error\n");
return 1;
}
printf("tm_wday=%d, asctime=%s\n", tm.tm_wday, asctime(&tm));
if ((t=mktime(&tm)) == (time_t)-1){
perror("mktime");
return 1;
}
printf("new asctime=%s\n", asctime(localtime(&t)));
}
prev parent reply other threads:[~1996-04-09 4:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-04-03 5:00 Retrieving the day of week rossier
1996-04-09 4:00 ` Tony Jones [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox