水一篇博客。。。
#include <ctime>
void unixTime2Str(long long n, char strTime[], int bufLen)
{
struct tm tm = *localtime((time_t *)&n);
strftime(strTime, bufLen - 1, "%Y-%m-%d %H:%M:%S", &tm);
strTime[bufLen - 1] = '\0';
}
嗯,参数n用的long long 。我看别人都是int
我这里不行。因为time_t是int64类型,所以还是longlong吧。
转换效果: