我正在尝试使用 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
关于c - 在 c 中用 ctime 格式化 Unix 时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12286369/