Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert Linux timestamp and date into function

Shulou Source: shulou.com Published: 2022-06-03 05:55:32 11月18日 Update

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

Tags: Function date time content analysis professional small and medium rich in content that is articles more knowledge articles industry perspective information information channels channels related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Huawei Xiaomi Apple