Linux的date常用操作

Linux的date常用操作

## 在指定的日期上减1天
$ date -d "2012-04-10 -1 day " +%Y-%m-%d
2012-04-09

## 在指定的日期上加1天
$ date -d "2012-04-10 +1 day " +%Y-%m-%d
2012-04-11

## 当前日期减1周
$ date -d "-1 week " +%Y-%m-%d
2012-04-15

## 当前日期加1周
$ date -d "+1 week " +%Y-%m-%d
2012-04-29

## 当前日期加1月
$ date -d "+1 month " +%Y-%m-%d
2012-05-22

## 当前日期减1月
$ date -d "-1 month " +%Y-%m-%d
2012-03-22

## 当前日期减1年
$ date -d "-1 year " +%Y-%m-%d
2011-04-22

## 当前日期加1年
$ date -d "+1 year " +%Y-%m-%d
2013-04-22

## 当前日期减1小时
$ date -d "-1 hour" +"%Y-%m-%d %H"
2018-06-27 18

## 当前日期加1小时
$ date -d "+1 hour" +"%Y-%m-%d %H"
2018-06-27 20

## 在指定的日期上加指定天
$ date -d "20150416 12 3 days" +"%Y%m%d%H"
2015041912

## 在指定的日期上加上指定的小时
$ date -d "20150416 12 3 hour" +"%Y%m%d%H"
2015041615

## 在指定的日期上减去指定的小时
$ date -d "20150416 12 -1 hour" +"%Y%m%d%H"
2015041611

## 在指定的日期上加上指定的分钟
$ date -d "20150416 12:20 10 minute" +"%Y%m%d%H%M"
201504161230

## 当前时间转时间戳
$  date -d "0 day ago" +%s
1528961461

## 指定时间转时间戳
$  date -d "20180614" +%s
1528905600
posted @ 2018-06-29 18:50  Python魔法师  阅读(338)  评论(0编辑  收藏  举报