Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert Linux timestamp and date into function

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report