String representation of time_t?

前端 未结 9 783
悲&欢浪女
悲&欢浪女 2020-12-09 02:05
time_t seconds;
time(&seconds);

cout << seconds << endl;

This gives me a timestamp. How can I get that epoch date into a string?<

9条回答
  •  Happy的楠姐
    2020-12-09 02:29

    the function "ctime()" will convert a time to a string. If you want to control the way its printed, use "strftime". However, strftime() takes an argument of "struct tm". Use "localtime()" to convert the time_t 32 bit integer to a struct tm.

提交回复
热议问题