#include <stdio.h>
#include <time.h>
int main() {
// 获取当前时间(以秒为单位的时间戳)
time_t rawtime;
time(&rawtime);
// 将时间戳转换为本地时间(struct tm)
struct tm * timeinfo = localtime(&rawtime);
// 使用strftime函数将struct tm转换为可读的字符串格式
char buffer[80];
strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
// 打印结果
printf("当前时间是: %s\n", buffer);
return 0;
}
C++——时间戳转年月日时分秒格式
最新推荐文章于 2024-08-24 18:25:54 发布