Linux under time_t Time type
The time_t type is defined in the Time.h header file:
#ifndef __time_t
#define __TIME_T
typedef long time_t;
#endif
Visible, time_t is actually a long integer type. The value is expressed as the number of seconds from UTC (Coordinated Universal Time) January 1, 1970 00:00 00 seconds (also known as the Linux system epoch) to the current moment. Because of the time_t type length, it represents a time that cannot be later than January 19, 2038 03:14 07 seconds (UTC). In order to be able to represent a longer time, you can save the calendar time with 64-bit or longer cosmetic numbers, which are not detailed here.
Use the time () function to get the time_t value of the current period and use the CTime () function to convert the time_t to a local time string.
Note: UTC time is sometimes referred to as GMT time, in fact UTC and GMT are almost identical concepts. They all refer to Greenwich Mean time, but UTC is a more formal term. The difference is that the former is an astronomical concept, and the latter is based on an atomic clock.
The format for printing time under Linux is:
printf ("%lu\n", time);
Linux usually involves the printing of time parameters: for example, get the file attribute stat function, which is a prototype:
int stat (const char *path, struct stat *buf);
BUF is a file information structure body, the structure body members are as follows:
struct stat {
dev_t st_dev;/* ID of device containing file/
ino_t St _ino; /* inode Number * *
mode_t st_mode; /* Protection * *
nlink_t st_nlink; /* Number of hard links
* /uid_t st_uid; /* User ID of owner
* /gid_t st_gid; /* Group ID of owner
* /dev_t St_rdev; /* Device ID (if special file) * *
off_t st_size; /* Total size, in bytes *
/blksize_t st_blksize/* blocksize for filesystem I/O blkcnt_t st_blocks;
/* number of 512B blocks allocated * *
time_t st_atime; /* Time of the last access * *
time_t st_mtime; /* Time of the last modification * *
time_t st_ctime; /* Time of last status change *
/};
The Shmctl function in the shared memory will also involve the time parameter, so it is unavoidable to print it in the Linux development.