Linux:: Time calendar command [2]: date command and timestamp (and conversion between date and timestamp)

Preface: This article is the content of the basic Linux operation chapter!
The environment I use is based on Tencent Cloud Server: CentOS 7.6 64bit.


Study set:


Directory index:
1. Understanding timestamps
2. How to obtain timestamps under Linux: date +%s
3. Time => timestamp
4. Timestamp => time: and necessary instructions
5. Recommended related articles or series


1. Understanding timestamps

Unix timestamp (Unix epoch, Unix time, POSIX time or Unix timestamp in English)

  • Unix timestamp : It is the number of seconds since January 1, 1970 (midnight UTC/GMT), regardless of leap years .

2. How to obtain timestamp under Linux: date +%s

Syntax format: date +%s

[Mortal@VM-12-16-centos test_txtfile]$ date +%s
1685263957		/* 这个数字就是时间戳 */

3. Time => timestamp

Syntax format: date +%s [Usage is the same as above!

[Mortal@VM-12-16-centos test_file]$ date +%s
1685974117

4. Timestamp => Time: and necessary instructions

  • Syntax format: date -d@timestamp

  • Note: @ is followed directly by the timestamp value to be converted.

  • The starting time given by domestic machines is: 08:00:00; reason: Beijing time starting point (theoretically it is Greenwich Time, the difference comes from time zone differences)

[Mortal@VM-12-16-centos test_txtfile]$ date -d@1685263957
Sun May 28 16:52:37 CST 2023
    
[Mortal@VM-12-16-centos test_txtfile]$ date -d@0
Thu Jan  1 08:00:00 CST 1970	/* 注:此处是北京时间起始点(理论上是格林尼治时间,差异来源于时区差异) */
[Mortal@VM-12-16-centos test_txtfile]$ date -d@1
Thu Jan  1 08:00:01 CST 1970

5. Recommendations for related articles or series

1. Linux learning directory collection ;


2. Linux:: Time calendar command [1]: date command: formatted display of time information, obtaining time under Linux


Guess you like

Origin blog.csdn.net/weixin_53202576/article/details/131057145