Linux :: 时间日历指令【2】:date 指令 与 时间戳(及日期与时间戳的相互转换)

前言:本篇是 Linux 基本操作篇章的内容!
笔者使用的环境是基于腾讯云服务器:CentOS 7.6 64bit。


学习集:


目录索引:
1. 时间戳的认识
2. Linux 下获取时间戳方式:date +%s
3. 时间 => 时间戳
4. 时间戳 => 时间:及必要说明
5. 相关文章或系列推荐


1. 时间戳的认识

Unix 时间戳(英文为Unix epoch, Unix time, POSIX time 或 Unix timestamp)

  • Unix 时间戳:是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰年

2. Linux 下获取时间戳方式:date +%s

语法格式:date +%s

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

3. 时间 => 时间戳

语法格式:date +%s【用法同上!】

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

4. 时间戳 => 时间:及必要说明

  • 语法格式:date -d@时间戳

  • 说明:@ 后直接跟待转换的时间戳数值

  • 国内机器给的起始时间是:08:00:00;原因:北京时间起始点(理论上是格林尼治时间,差异来源于时区差异)

[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. 相关文章或系列推荐

1. Linux 学习目录合集


2. Linux :: 时间日历指令【1】:date 指令:格式化显示时间信息、Linux 下获取时间


猜你喜欢

转载自blog.csdn.net/weixin_53202576/article/details/131057145