在c中使用ctime格式化Unix时间戳

2023-11-21

我正在尝试使用 ctime 格式化 10 位 Unix 时间戳(当前是字符串)。

但是,ctime() 需要一个 time_t 类型的参数,而不是字符串。

在使用 ctime 之前我必须做什么? 换句话说,我可以轻松地将字符串转换为 time_t 吗?


你是说你有像 1346426869 这样的字符串并希望它成为 time_t ?

time_t raw_time = atoi("1346426869");
printf("current time is %s",ctime(&raw_time));

> current time is Fri Aug 31 11:27:49 2012
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在c中使用ctime格式化Unix时间戳 的相关文章

随机推荐