From: Joe Mario <mario@zk3.dec.com>
To: Jean-Claude Magras <magrasjc@texas.net>
Subject: Re: strftime problems?
Date: 1998/02/11 [thread overview]
Message-ID: <34E1FF76.59E2@zk3.dec.com> (raw)
In-Reply-To: 34D24759.F2815882@texas.net
Jean-Claude Magras wrote:
>
> I am contributing to a known freeware project and I am having trouble
> with strftime (on Digital UNix 3.2).. I use the "%T: meaning HH:MM:SS
> is the output string. I have checked the contents of the struct tm
> I pass in and they seem valid (that is the mt_hour/mt_min/mt_sec
> fields seem valid but strfime() usually reports "00:00:00". It
> sometimes puts an asterisk or slash in the hours field or
> occassionally a 12 or 3 but its never correct.
Here's some input from a strftime maintainer:
I can't be sure what the problem is from this limited
description. I'm assuming he mis-typed the tm field names
(tm_hour, tm_min, tm_sec) in this message, but not in the
program itself. If he wants to use %T as the output format,
I assume his code looks something like this:
. . .
char dtbuf[MAXSIZE];
time_t clock;
struct tm *timeptr;
clock = time ((long*)NULL);
timeptr = localtime(&clock);
strftime(dtbuf, MAXSIZE, "%T", timeptr);
printf("%s\n", dtbuf);
Of course, as an i18n person, I should point out this is
not a good way to code things. He should get the output
format from a locale. I looked at the Digital locales, and
virtually all of them use the equivalent of %T for their
time format (t_fmt). That means he needs to include <locale.h>
and <langinfo.h>, add a call to setlocale() at the beginning
of the program, and call strftime() this way:
strftime(dtbuf, MAXSIZE, nl_langinfo(T_FMT), timeptr);
Then it should work.
prev parent reply other threads:[~1998-02-11 5:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-01-30 5:00 strftime problems? Jean-Claude Magras
1998-02-11 5:00 ` Joe Mario [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