From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,27872f554944093c X-Google-Attributes: gidfc89c,public X-Google-Thread: fee84,27872f554944093c X-Google-Attributes: gidfee84,public From: Joe Mario Subject: Re: strftime problems? Date: 1998/02/11 Message-ID: <34E1FF76.59E2@zk3.dec.com>#1/1 X-Deja-AN: 324203705 Content-Transfer-Encoding: 7bit References: <34D24759.F2815882@texas.net> To: Jean-Claude Magras Content-Type: text/plain; charset=us-ascii Organization: UBPG Mime-Version: 1.0 Newsgroups: comp.unix.osf.osf1,comp.unix.programmer 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 and , 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.