Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add some specific time while using the linux command "date"

Tags:

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?

like image 632
waitingkuo Avatar asked Apr 22 '13 08:04

waitingkuo


People also ask

How do I run a command at a specific time in Linux?

Using at. From the interactive shell, you can enter the command you want to run at that time. If you want to run multiple commands, press enter after each command and type the command on the new at> prompt. Once you're done entering commands, press Ctrl-D on an empty at> prompt to exit the interactive shell.

What is date/time command in Linux?

date command is used to display the system date and time. date command is also used to set date and time of the system. By default the date command displays the date in the time zone on which unix/linux operating system is configured. You must be the super-user (root) to change the date and time.


1 Answers

On Linux

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

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

For example:

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

On Mac OS

Warning, the above only works on Linux, not on Mac OS.

On Mac OS, the equivalent command is

date -v+1H 
like image 59
fedorqui 'SO stop harming' Avatar answered Oct 08 '22 19:10

fedorqui 'SO stop harming'