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 use the localtime_r () and localtime () functions in linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the linux localtime_r () and localtime () function how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Localtime_r () localtime () gets the local current time and date

The function prototype is as follows:

1 # include 2 3 struct tm * localtime (const time_t * timep); 4 struct tm * localtime_r (const time_t * timep, struct tm * result) 5 6 / * this function will have the value obtained by the time function timep to convert the time and date representation used in the real world, and then return the result from the structure tm to * / 7 8 / * * it should be noted that the localtime function can convert time to local time, but the localtime function is not thread safe. 9 in multithreaded applications, the localtime_r function should be used instead of the localtime function, because localtime_r is thread-safe * * / eg:

1 # include 2 # include 3 # include 4 5 int main () 6 {7 time_t timep; 8 struct tm * p; 9 10 time (& timep); 11 p = localtime (& timep) 12 13 printf ("% d-%d-%d% d:%d:%d\ n", (1900 + p-> tm_year), (1 + p-> tm_mon), p-> tm_mday, 14 (p-> tm_hour + 12), p-> tm_min, p-> tm_sec); 15 16 return 0 17} Thank you for reading this article carefully. I hope the article "how to use the localtime_r () and localtime () functions in linux" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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