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.
精彩评论