Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to get time in Linux system

Shulou Source: shulou.com Published: 2022-06-01 20:50:25 11月04日 Update

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

Tags: Time function process week format structure hour character system decimal decimal two result kernel unit command string year time zone user Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia macOS Redmi vpn