How to: Check/Change/Set/Modify Linux (Debian/Ubuntu/Kali Linux/CentOS) date/time/timezone etc. (and Calculate past/future date/time) in Terminal

Last Updated on

Check/Calculate time

Show current time

date
date
date

Calculate past/future time

date --date="1 day ago"
 
date --date="2 hours ago"
 
date --date="3 days"
 
date --date="2 hours"
Calculate dates/time
Calculate dates/time

timedatectl
 
timedatectl status
timedatectl
timedatectl
timedatectl status
timedatectl status

Show/Change timezone

Show timezone

timedatectl list-timezones

Set timezone

timedatectl set-timezone Africa/Abidjan

Change time by using “timedatectl”

(HH:MM:SS, in 24 hour format)

sudo timedatectl set-time 00:00:00
Use timedatectl set-time to change time
Use timedatectl set-time to change time

Change time by using “date”

(HH:MM:SS, in 24 hour format)

sudo date +%T -s "23:00:00"

(12 hour format)

sudo date +%T%p -s "2:00:00AM"
 
sudo date +%T%p -s "2:00:00PM"

Change date

Set the date and time to 03 Feb 2001, 01:00:00

sudo date --set="20010203 01:00:00"
 
sudo timedatectl set-time '2001-02-03 01:00:00'

Set date

sudo timedatectl set-time 2001-02-03
 
sudo date --date="2001-02-03"

Create custom date format (+)

sudo date +"Year : %Y Day : %d Month : %m"
 
# Output
Year : 2001 Day : 03 Month : 02
 
sudo +%D
 
# Output
02/03/01
 
sudo date +"%a %b %d %y"
 
# Output
Sat Feb 03 01
 
sudo date +"%A %B %d %Y"
 
# Output
Saturday February 03 2001
 
sudo date +"%A %B %d %Y %T"
 
# Output
Saturday February 03 2001 00:27:30
 
sudo date +"%A %B-%d-%Y %c"
 
# Output
Saturday February-03-2001 Sat 03 Feb 2001 00:28:17 EST

%D: Year/Month/Day format.

Show CMOS Time

sudo hwclock
hwclock
hwclock

Leave a Reply

Your email address will not be published. Required fields are marked *