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

标签 c unix unix-timestamp ctime

我正在尝试使用 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/

相关文章:

c++ - OpenMP 中的本地指针

c - chardev 的主要和次要模式有多稳定?

r - 将数字(integer64 类)UNIX 时间戳转换为日期时间类

c - 将 ceil 的结果转换为整数是否安全?

c - 在 C 中分配和使用对齐的 double 组

linux - libstdc++.so.6 : version not found - NO admin rights

c - GNU readline 历史功能

php - 如何在 postgresql 上使用 unix 时间戳

PHP 日期 4 周前

c++ - 具有 WinAPI 的真正 transient 窗口?