C语言 时间戳转换

#include "stdio.h"
#include "time.h"
#include "string.h"
 
char *t2t(time_t tick)
{
	struct tm tm;   
	static char s[100]; 
	memset(s, 0, sizeof(s));
	tm = *localtime(&tick);  
	strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm);  
	return s;	
}

int main()
{
	int t = time(NULL); // 获取当前时间戳
	printf("%d\n", t);
	puts(t2t(t));
	return 0;
}

执行结果

1591177089
2020-06-03 17:38:09

你可能感兴趣的:(Windows编程)