Mellnik Mellnik - 2 months ago 36
C++ Question

UnixTime to readable date

Possible Duplicate:

C++: Get current time and date

What is the best way to convert UnixTime to a date?

Is there a function for it or an algorithm?


Unix time is seconds since epoch (1970-01-01). Depending on what you mean, you can convert it to a struct tm with localtime or convert it to a string with strftime.

time_t t = time(NULL);
struct tm *tm = localtime(&t);
char date[20];
strftime(date, sizeof(date), "%Y-%m-%d", tm);