* Retrieving the day of week
@ 1996-04-03 5:00 rossier
1996-04-09 4:00 ` Tony Jones
0 siblings, 1 reply; 2+ messages in thread
From: rossier @ 1996-04-03 5:00 UTC (permalink / raw)
Hello OSF World,
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
language. This should be usable in the whole countries of world (that
means to be not dependent of the GMT offset).
-> The strptime function does not update the wday field in the
structure tm.
Good luck.
You may leave a mail to rossier@nagra-kudelski.ch
Daniel Rossier
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Retrieving the day of week
1996-04-03 5:00 Retrieving the day of week rossier
@ 1996-04-09 4:00 ` Tony Jones
0 siblings, 0 replies; 2+ messages in thread
From: Tony Jones @ 1996-04-09 4:00 UTC (permalink / raw)
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)));
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-04-09 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-04-03 5:00 Retrieving the day of week rossier
1996-04-09 4:00 ` Tony Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox