How to convert Linux timestamp and date into function
In this issue, the editor will bring you about the Linux timestamp and date conversion function. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Linux timestamp, date conversion function:
# include # include using namespace std;time_t date_to_timestamp (char * date, char * pfmt) {struct tm t; strptime (date, pfmt, & t); time_t tt = mktime (& t); return tt;} string timestamp_to_date (time_t tt) {struct tm * t = localtime (& tt); char dateBuf [128] Snprintf (dateBuf, sizeof (dateBuf), "d-d-d d:d:d", t-> tm_year+1900, t-> tm_mon+1, t-> tm_mday, t-> tm_hour, t-> tm_min, t-> tm_sec); string date (dateBuf); return date;} int main () {/ * time_t tt = 1372225160; string date = timestamp_to_date (tt) Cout