Back to Blog
Linux setdate5/6/2023 ![]() ![]() * 15: Second (ss) Change Timezone in Linux To manually set the time in Linux, use the following syntax: To manually set a new date and time in Linux, use the following syntax: You can use the date command to display the current date and time: We hope we have shed light on the use of the Linux date command, and we trust you can use it to display the system’s date and customize the output to your preference.Are you a Linux user trying set or change the date, time, or timezone on your Linux Server? Read on to learn how to display the current date, manually change the system date and time, and set timezones in Linux using the command line and these simple commands. Sometime while creating a shell script, we save date command to a variable and then later we create log file using that variable, examples is shown below, #!/bin/bashĮcho "#Check Cluster for Failed Resources#" > $LOGFILEĮcho "#Check Cluster for Stopped Resources#" > $LOGFILEĬrm_mon -1 -rf | grep -i STOPPED > $LOGFILE $ sudo timedatectl set-timezone Asia/Kolkata 8) Using Date command in variable In case you want to change time zone then use timedatectl command, example is shown below. We have a detailed guide on how to sync time and date using chrony. In fact, modern systems such as CentOS 8 / RHEL 8 don’t support NTP. ![]() A better way to achieve this is to use the chrony utility which is a replacement for the now deprecated ntpd daemon. Setting the system’s date and time this way is discouraged since the time is most likely to be inaccurate. For example, to set the date and time to 25, June 2021 at 11:15 am, run the command: $ sudo date -set="20210625 11:15" The date command also allows you to set the date and time. To print the day of the week, month, year, and current time run: $ date "+%A %B %Y %T" The syntax for using the date option is quite simple:įor example, to print the date in yy/mm/dd format, run $ date "+%Y-%m-%m" %a – Weekday in shortened format (e.g., Fri).%A – Weekday in full string format(e.g., Friday).%b – Month name in the shortened string format (e.g., Feb).%B – Month name in the full string format (e.g., February).%D – Display date in the format mm/dd/yy.Listed below are some of the formatting options available. The date command comes with many options that allow you to customize the date output. To display the date 4 months from now run: $ date -date="4 months"Īnd to check the date 2 years from now run: $ date -date="2 years" To display what the date will be in two weeks’ time execute: $ date -date="2 weeks" To check what the date will be exactly a week from now, run: $ date -date="next week" Just as you can check past dates, the date command also allows you to display future dates.įor example, to check tomorrow’s date run: $ date -date="tomorrow" $ 5) Use the date command to check future dates To print the date 3 years ago, run: $ date -date="3 years ago" To check the date three months ago, execute: $ date -date="3 months ago" To view the date two weeks earlier, run the command: $ date -date="2 weeks ago" The date command can also print the date and time in the past relative to your current date.įor example, to check what the date was 9 days ago run the command. $ 4) Use the date command to check past dates Take note that this does not affect your system’s date and time, rather it simply converts the date format to a string. You can display a specific date in a string format using the –date option as illustrated below. $ 3 ) Display a specific date in a string format To display time in UTC (Coordinated Universal Time ),previously referred to as GMT (Greenwich Mean Time), append the -u option. In its basic form, without any command options, the date command displays your current date and time including the day of the week, month, year, the time in hh:mm:ss format, and the timezone as presented below. 5) Use the date command to check future dates.4) Use the date command to check past dates.3 ) Display a specific date in a string format.
0 Comments
Read More
Leave a Reply. |