In linux, date
can help me to print the current time. If want to print the current time + 1 hour, what option should I give?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Date with SimpleDateFormat in Java
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
According this source you can just do:
Linux and macOS in a single command
If you need to write scripts that work on both Linux servers and macOS workstations, you can silence the error of the first
date
call and 'OR' it (||
) with the other. It doesn't matter which comes first.For example, this bash function uploads a file to AWS S3 and sets a
Expires:
andCache-Control:
headers.In shell script, if we need to add time then use below command and date format(PUT TIME before DATE string)
date -d"11:15:10 2017-02-05 +2 hours" +"%Y-%m-%d %H:%M:%S"
this will output2017-02-05 13:15:10
THis does not result in correct date without UTC it does not work
TZ=Asia/Calcutta date
should work (obviously this will get you the time in Calcutta).This changes your TimeZone (
TZ
) environment variable for this operation only, it won't permanently set you to the new time zone you specify.We can get it using below code, i was handling a case wherein i required to traverse dates from last 3 months, i used below code to traverse the same
!/bin/sh
On Linux
Just use
-d
(or--date
) to do some math with the dates:For example:
On Mac OS
Warning, the above only works on Linux, not on Mac OS.
On Mac OS, the equivalent command is