开发者

A question about strftime

开发者 https://www.devze.com 2022-12-20 16:11 出处:网络
The question is simple \"Say we have an integer 1 <= n <= 12,How to use strftime to display Janua开发者_如何学编程ry for \'1\',February for \'2\',March for \'3\' and so on ... ?\"#include <st

The question is simple "Say we have an integer 1 <= n <= 12,How to use strftime to display Janua开发者_如何学编程ry for '1',February for '2',March for '3' and so on ... ?"


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

size_t monthName( char* buf, size_t size, int month)
{
    struct  tm t = {0};

    t.tm_mon = month - 1;   // turn month 1..12 to 0..11 as `struct tm` wants

    return strftime( buf, size, "%B", &t);
}


int main(int argc, char* argv[])
{
    char buf[10];

    monthName( buf, sizeof( buf), 9);
    printf( "%s\n", buf);
    return 0;
}


struct tm tm = {0};
tm.tm_mon = n - 1;
strftime(s, len, "%B", &tm);
0

精彩评论

暂无评论...
验证码 换一张
取 消