문제

I'm trying to format a 10-digit Unix time stamp (currently a string) using ctime.

However, ctime() expects a parameter of type time_t, not a string.

What must I do before I can use ctime? In other words, can I easily convert the string into a 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

다른 팁

The time_t type is just an integer. It is the number of seconds since the Epoch. You'll need to parse the string first.

Start here:

http://www.gnu.org/software/libc/manual/html_node/General-Time-String-Parsing.html#General-Time-String-Parsing

and work your way forward from there.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top