struct tm * stm = NULL;
long ltime = atol("1290140656");
stm = localtime(<ime);
printf("Local hour is: %d-%d-%d %d:%d:%d\n",stm->tm_year+1900,stm->tm_mon+1,stm->tm_mday,
stm->tm_hour,stm->tm_min,stm->tm_sec);
Local hour is: 2010-10-19 2:7:35
本文展示了一个使用C语言进行时间戳转换为本地时间的例子。通过解析代码,演示了如何利用atol函数将字符串形式的时间戳转换为long类型,再使用localtime函数将其转化为struct tm类型,最终通过printf函数打印出易读的时间格式。
1142

被折叠的 条评论
为什么被折叠?



