Re: Strftime Mingw don't work

Discussion in 'C Programming' started by Keith Thompson, Jan 2, 2013.

  1. "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",
    tm_now);
    if (result == 0) {
    fprintf(stderr, "strftime() failed\n");
    exit(EXIT_FAILURE);
    }

    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) <http://www.ghoti.net/~kst>
    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"
    Keith Thompson, Jan 2, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan O'Malley

    strftime not working as expected

    Bryan O'Malley, Feb 3, 2004, in forum: C++
    Replies:
    8
    Views:
    2,616
    Jerry Coffin
    Feb 17, 2004
  2. Sam Smith
    Replies:
    0
    Views:
    1,160
    Sam Smith
    Oct 18, 2004
  3. Bimal
    Replies:
    1
    Views:
    453
    Tim Prince
    Aug 20, 2003
  4. xeno fears
    Replies:
    1
    Views:
    493
    Martin v. Löwis
    Oct 4, 2009
  5. Lew Pitcher

    Re: Strftime Mingw don't work

    Lew Pitcher, Jan 2, 2013, in forum: C Programming
    Replies:
    7
    Views:
    240
    James Kuyper
    Jan 5, 2013
Loading...

Share This Page