Shell Date Usage Example
Here are some examples to formate Date in shell
# get current time in year-month-dateThour:minuteZ format
|
1 2 3 4 |
>> date +'%Y-%m-%dT%H:%MZ' 2016-06-21T01:09Z |
# get the time an hour ago
|
1 2 3 4 |
>> date -d "1hours" +'%Y-%m-%dT%H:00Z' 2016-06-21T02:00Z |
# Get the date with hour == 0
|
1 2 3 4 |
>> date +'%Y-%m-%dT00:00Z' 2016-06-21T00:00Z |
#more examples
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
>> date -d "-1 day" +'%Y-%m-%dT00:00Z' 2016-06-20T00:00Z >> date -d "-2 days" +'%Y-%m-%dT00:00Z' 2016-06-19T00:00Z >> date -d "-3 days" +'%Y-%m-%dT00:00Z' 2016-06-18T00:00Z >> date -d "-2hours" +'%Y-%m-%dT%H:00Z' 2016-06-20T23:00Z >> date -d "-30 day" +'%Y-%m-%dT00:00Z' 2016-05-22T00:00Z >> date +'%Y-%m-%dT07:00Z' 2016-06-21T07:00Z >> date +'%Y-%m-%dT09:00Z' 2016-06-21T09:00Z |











