#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
// 1秒等于1000毫秒,等于1000000微秒
int main(int argc, char argv[])
{
time_t st_mtime;
struct tm local_time;
char mtime[21] = { 0 };
time(&st_mtime);
localtime_r(&st_mtime, &local_time); // 这个函数是线程安全的
strftime(mtime, sizeof(mtime), "%F %T", &local_time);
printf("年月日 时分秒:%s\n", mtime);
strftime(mtime, sizeof(mtime), "%m-%d %T", &local_time);
printf("月日 时分秒:%s\n", mtime);
char buffer[64] = { 0 };
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &local_time);
printf("格式化的日期 & 时分秒: %s\n", buffer );
return 0;
}
05-29
3441
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-05
559
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-23
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交