How to get time in Linux system
This article is about how to get time in Linux system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
There are two kinds of Linux system times.
(1) calendar time. This value is the cumulative number of seconds that have elapsed since 00:00:00 coordinated Universal time (UTC) on January 1, 1970. Basic data types are saved in time_t. Finally, through the conversion, we can get the 24-hour system or 12-hour interval time we usually see.
(2) process time. Also known as CPU time, it measures the CPU resources used by the process. The process time is calculated by clock tick.
This article will give you a detailed introduction to the acquisition and use of Linux time. Let's take a look at the detailed introduction.
Get timestamp
Time ()
# include time_t time (time_t * calptr)
Time returns the timestamp of the current time, that is, the number of seconds from UTC to the present
Time_t is actually a uint64_t.
When calptr is not empty, the timestamp is also written to the pointer
Call example:
# include # include # include using namespace std;int main () {time_t curTime;curTime = time (NULL); cout