gpt4 book ai didi

c++ - 关于strftime的一个问题

转载 作者:太空宇宙 更新时间:2023-11-04 00:56:15 24 4
gpt4 key购买 nike

问题很简单“假设我们有一个整数1 <= n <= 12,如何使用strftime显示一月1”,二月为“2”,三月为“3”等等……?”

最佳答案

#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;
}

关于c++ - 关于strftime的一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2305044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com