如何才能用C语言代码帅气地获取现在是今年的第几天呢?

xiaoxiao2021-02-28  137

答案是:

localtime()函数:获取当前时间和日期并转换为本地时间

C++代码如下:

#include <iostream> #include <ctime> using namespace std; int main(void) { time_t t = time(0); char nowtime[64]; strftime(nowtime,sizeof(nowtime),"%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t)); cout<<nowtime<<endl; }

转载请注明原文地址: https://www.6miu.com/read-25810.html

最新回复(0)