shell:脚本中标准时间与Unix时间戳之间的转换

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

是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。

UNIX时间戳的0按照ISO 8601规范为 :1970-01-01T00:00:00Z.

一个小时表示为UNIX时间戳格式为:3600秒;一天表示为UNIX时间戳为86400秒,闰秒不计算。

标准时间与时间戳之间的转换

1,获取当前标准时间

currentTime=`date “+%Y-%m-%d %H:%M:%S”`

2,获取当前时间戳

currentStamp=`date +%s`

3,将标准时间转换成时间戳

standard="2016-08-03 14:13:23"               //注意格式一定要正确
stamp=`date -d "$standardTime" +%s`

4,将时间戳转换成标准时间

stamp=1287331200
standard=`date -d @"$stamp" +"%Y-%m-%d %H:%M:%S"`

原文:https://blog.csdn.net/wangqing_12345/article/details/52104764

posted @ 2019-04-18 16:17  M1927  阅读(426)  评论(0)    收藏  举报