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

Time arrangement in Unix

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Historically, two different types of time values have been used in Unix systems:

1. Calendar time. This value is the cumulative value of the description experienced since UTC (or Greenwich mean time). The basic data type of the corresponding system is time_t.

2. Process time. Also known as CPU time, is used to measure the CPU resources used by the process. Expressed by clock ticks, the corresponding basic data type of the system is clock_t.

In addition, the following data types that represent time are defined in the unix system:

Struct tm: formatted decomposed time information with multiple fields, including seconds, minutes, hours, dates, months, years, weeks, days of the year, etc.

Struct timeval: two fields, seconds and microseconds, together represent a time, and the highest precision is microseconds.

Struct timespec: there are two fields, seconds and nanoseconds, which represent time with two kinds of precision.

The basic data types time_t, clock_t, and several other structures that represent time can be linked by the following system call functions:

Time_t time (time_t * t); int clock_gettime (clockid_t clk_id, struct timespec * tp); int gettimeofday (struct timeval * tv, struct timezone * tz)

In addition to the first time, there are some library functions you can use:

Transform date and time to broken-down time or ASCII

# include char * asctime (const struct tm * tm); char * asctime_r (const struct tm * tm, char * buf); char * ctime (const time_t * timep); char * ctime_r (const time_t * timep, char * buf); struct tm * gmtime (const time_t * timep); struct tm * gmtime_r (const time_t * timep, struct tm * result); struct tm * localtime (const time_t * timep) Struct tm * localtime_r (const time_t * timep, struct tm * result); time_t mktime (struct tm * tm)

Where to use:

1. The st_atime, st_mtime and st_ctime of the file all use the data type struct timespec.

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

Servers

Wechat

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

12
Report