Add specific time when using the linux "date" command

On linux, date can help me print the current time. If you want to print the current time + 1 hour, what option should I give?

+6
source share
5 answers

Just use -d (or --date ) to do some math with dates:

 date -d '+1 hour' '+%F %T' # ^^^^^^^^^^^^ 

For instance:

 $ date '+%F %T' 2013-04-22 10:57:24 $ date -d '+1 hour' '+%F %T' 2013-04-22 11:57:24 # ^ 
+24
source

According to this source, you can simply:

date --date = '1 hour'

+1
source

TZ=Asia/Calcutta date should work (obviously this will give you time in Calcutta).

This changes your environment variable TimeZone ( TZ ) only for this operation, it will not constantly set you in the new time zone that you specified.

0
source

We can get it using the code below, I handled the case when I had to go through dates from the last 3 months, I used the code below to go through the same

! / Ben / w

 for i in {90..1} do st_dt=$(date +%F' 00:00:00' -d "-$i days") echo $st_dt j=$((i-1)) end_dt=$(date +%F' 00:00:00' -d "-$j days") echo $end_dt done 
0
source

In the shell script, if we need to add time, use the command and date format below (PUT TIME before the DATE line)

date -d"11:15:10 2017-02-05 +2 hours" +"%Y-%m-%d %H:%m:%d" this will display 2017-02-05 13:15:10

0
source

All Articles