date
command. However, you may need administrative (root) privileges for this operation. Here are the basic commands for performing the date and time change;Changing Date and Time on Linux:
- Displaying Current Date and Time:
date
Shows the current date and time.
- Setting a New Date and Time:
sudo date MMDDhhmm[[CC]YY][.ss]
For example, the command “112522002021.30” sets the date to November 25, 2021, at 22:00:30.
- Setting Time Zone:
sudo dpkg-reconfigure tzdata
Interactively sets the time zone.
- Time Synchronization (Using NTP):
sudo apt-get install ntp # Ubuntu/Debian sudo yum install ntp # CentOS/Fedora sudo systemctl start ntp
Enables time synchronization using NTP (Network Time Protocol).
Changing Date and Time on Windows:
- Navigating to Date and Time Settings in the Taskbar: Right-click on the clock and choose “Settings” or “Date and time settings.”
- Setting a New Date and Time: Use the “Change” option in the settings window to enter new date and time information.
- Setting Time Zone: Adjust the time zone through the “Region and language” or “Time and language” settings.
- Using Internet Time Service: Enable “Synchronize with an internet time server” under the “Internet Time” tab in the settings window.
Note: The steps in Windows might vary depending on the version and language settings. If you have trouble finding specific windows or menu names, consulting documentation specific to your language and version can be helpful.
Date Command Cheat Sheet:
- Display Current Date and Time:
date
Displays the current date and time.
- Display Date in a Specific Format:
date +"%Y-%m-%d %H:%M:%S"
Displays the date and time in a custom format. Modify the format specifier as needed.
- Set Date and Time:
sudo date MMDDhhmm[[CC]YY][.ss]
Sets the system date and time. Replace MM, DD, hh, mm, CC, YY, and ss with the desired values.
- Display UTC (Coordinated Universal Time):
date -u
Displays the current UTC time.
- Display Date and Time of a Specific File:
date -r filename
Shows the last modification time of a file.
- Display Date Without Time:
date +"%Y-%m-%d"
Displays the current date without the time.
- Display Date of Tomorrow:
date -d "tomorrow"
Shows the date of tomorrow.
- Display Day of the Week:
date +"%A"
Displays the current day of the week.
- Set Hardware Clock from System Clock:
sudo hwclock --systohc
Synchronizes the hardware clock with the system clock.
- Display Calendar for a Specific Month:
cal -m MM YYYY
Displays the calendar for a specific month. Replace MM and YYYY with the desired month and year.
- Convert Date to Epoch (Unix Timestamp):
date +%s
Shows the current date and time in Epoch format.
- Calculate Future/Past Date:
date -d "today + 5 days"
Calculates the date for a specific number of days in the future or past.
Remember to adapt these commands based on your specific needs, and feel free to explore more options by checking the date
command’s manual (man date
).