格式化Unix时间戳在C的ctime [英] Formatting Unix timestamp with ctime in c
本文介绍了格式化Unix时间戳在C的ctime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用格式化的ctime一个10位Unix的时间戳(当前字符串)。
I'm trying to format a 10-digit Unix time stamp (currently a string) using ctime.
然而,的ctime()预计time_t类型的参数,而不是字符串。
However, ctime() expects a parameter of type time_t, not a string.
我必须做什么之前,我可以使用的ctime?
换句话说,我可以很容易地将字符串转换成time_t的?
What must I do before I can use ctime? In other words, can I easily convert the string into a time_t?
推荐答案
您是说您有类似1346426869作为一个字符串,并希望它成为一个time_t的?
You're saying you have something like 1346426869 as a string and want it to be a 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
这篇关于格式化Unix时间戳在C的ctime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文