How to set and view system date & time using date command

How to set and view system date & time using date command

date command is used to display the system date and time. date command is also used to set date and time of the system. 

    1.   To display the current date and local time, type the following at a shell prompt:
# date 
Mon Sep 17 17:30:24 EDT 2018
    
     2.   To display the current date and time in UTC, type the following at a shell prompt:
 # date -u
Mon Sep 17 17:30:24 UTC 2018
    
     3.   To change the current date & time, run the date command with the --set or -s option as root:
# date –s ’17-sep-2018 17:00’
   
     4.   To change the current time
# date –s 15:40:30 

  
Using - -date or –d option for displaying past dates:

· Date and time of 2 years ago.
Command:
$date --date="2 year ago"
Output:
Sat Oct 10 23:42:15 PDT 2019

· Date and time of 5 seconds ago.
Command:
$date --date="5 sec ago"
Output:
Tue Oct 10 23:45:02 PDT 2018

· Date and time of previous day.
Command:
$date --date="yesterday"
Output:
Mon Oct 9 23:48:00 PDT 2018

· Date and time of 2 months ago.
Command:
$date --date="2 month ago"
Output:
Thu Aug 10 23:54:51 PDT 2018

· Date and time of 10 days ago.
Command:
$date --date="10 day ago"
Output:
Sat Sep 30 23:56:55 PDT 2018

Using - -date option for displaying future date:

· Date and time of upcoming particular week day.
Command:
$date --date="next tue"
Output:
Tue Oct 17 00:00:00 PDT 2018

· Date and time after two days.
Command:
$date --date="2 day"
Output:
Fri Oct 13 00:05:52 PDT 2018

· Date and time of next day.
Command:
$date --date="tomorrow"
Output:
Thu Oct 12 00:08:47 PDT 2018

· Date and time after 1 year on the current day.
Command:
$date --date="1 year"
Output:
Thu Oct 11 00:11:38 PDT 2019

No comments:

Post a Comment