Mellnik Mellnik - 1 year ago 335
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?

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download