开发者

Converting a time_t to string

I have a time_t variable containing a timestamp which I'd like to store in开发者_JAVA技巧 a database, so I need it as a string. How would I convert it?

Also, on the subject, how would I convert a timestamp string into a time_t variable?

Thanks, Wyatt


Look at ctime, it takes a time_t and returns a string. To make a timestamp from a string, look at mktime. Populate the fields of a struct tm and call mktime. It should return a time_t.


Since it's tagged C++, I'd recommend this: istringstream http://www.cplusplus.com/reference/iostream/istringstream/

Works like a charm. Might require ostringstream as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜