问题描述
我一直在寻找一种方式来(大纪元中的时间)的字符串转换成日期。
I've been looking for a way to convert a string (in Epoch time) into a date.
基本上,我需要这样的: 1360440555
(以字符串形式),并把它变成这样: 2月9日12:09 2013
。
Basically, I need to take this: 1360440555
(in string form) and make it into this: Feb 9 12:09 2013
.
我一直在寻找strptime和strftime,但也似乎是为我工作。有什么建议?
I've been looking at strptime and strftime, but neither seems to be working for me. Any suggestions?
编辑:谢谢,伙计们。我把它转换为int与的atoi()
,强制转换为 time_t的
,然后跑的ctime()
就可以了。完美工作!
Thanks, guys. I converted it to an int with atoi()
, cast it as time_t
, then ran ctime()
on it. Worked perfectly!
推荐答案
如果只有你有一个整数,而不是一个字符串值,你可以只调用的ctime
。如果只是有一些方法来字符串转换为整数....
If only you had that value in an integer instead of a string, you could just call ctime
. If only there were some way to convert a string to an integer....
time_t c;
c = strtoul( "1360440555", NULL, 0 );
ctime( &c );
这篇关于转换大纪元字符串时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!