开发者

Converting a time_t to string

开发者 https://www.devze.com 2022-12-29 11:13 出处:网络
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?

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

精彩评论

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

关注公众号