Velocity Reviews

Velocity Reviews (
-   C Programming (
-   -   Re: Strftime Mingw don't work (

Keith Thompson 01-02-2013 05:16 PM

Re: Strftime Mingw don't work
"Bertram" <> writes:
> I try format date with compiler Mingw con function strftime.
> time_t t;
> char buffer[100];
> The option tha I use is:
> strftime(buffer,sizeof(buffer),DayDate="%d.%B.%Y.% A Time%H:%M:%S
> WeekYear=%U %W" ,(localtime ((time (&t), &t))));
> printf ("BUFFER=%s\n", buffer);
> But the option: %U or %W don't work!

How exactly does it not work? What output did you expect, and what
output did you actually get?

It works for me with MinGW under Cygwin, and should work with
any conforming C compiler. Here's the test program I used; I've
modified it from your code so it's a bit less convoluted (e.g.,
no assignments or comma operators in parameter expressions):

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
time_t time_now = time(NULL);
struct tm *tm_now = localtime(&time_now);

char buffer[100];

size_t result = strftime(buffer,
sizeof buffer,
"%d.%B.%Y.%A Time%H:%M:%S WeekYear=%U %W",
if (result == 0) {
fprintf(stderr, "strftime() failed\n");

printf ("BUFFER=\"%s\"\n", buffer);

return 0;

And here's the output:

BUFFER="02.January.2013.Wednesday Time09:12:29 WeekYear=00 00"

Keith Thompson (The_Other_Keith) <>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

All times are GMT. The time now is 01:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.