String representation of time_t?

前端 未结 9 790
悲&欢浪女
悲&欢浪女 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条回答
  •  天涯浪人
    2020-12-09 02:29

    The C++ way is to use stringstream.

    The C way is to use snprintf() to format the number:

     char buf[16];
     snprintf(buf, 16, "%lu", time(NULL));
    

提交回复
热议问题