GNU date is one of the many common Linux programs in
GNU Coreutils package. Here are some of the examples of performing date time arithmetic with GNU date command, using
-d
or
--date
option switch:
date -d "last month" +%m
Return as last month in numeric format
date -d "2 month ago" +%b
Return as last month in abbreviated month name
date -d "-2 month" +%B
Return as last month in full month name
date -d "-1 hours" +%H
Returns previous hour in 24-hours format (00-23)
date -d "tomorrow"
Return the date and time of tomorrow
date -d "yesterday" +"%d %B %y"
Return the date of yesterday in dd MMM yy
date -d "last week" +%a
Return last week in abbreviated weekday name
date -d "$(date +%Y-%m-15) -1 month" +'Last month was %B!'
To avoid getting result of “July” when executing date -d "-1 month" +%B
on 31 July 2006, because “2006-07-31 -1 month” might evaluate to 2006-07-01, because 2006-06-31 is an invalid date!
date -d "1970-01-01 00:00:01 UTC" +%s
Return the Unix Epoch time (the total seconds elapse since midnight of 1970-01-01), which is 1 secs in this case.
date -d "1970-01-01 1234567890 sec" +"%F %T %z"
Return the literal date format of the given Unix Epoch time.
No hay comentarios:
Publicar un comentario