Linux Display and Set Date From a Command Prompt

Linux Display Current Date and Time


You must login as root user to use date command.


Just type the date command:
$ date

Sample outputs:

Mon Jan 21 01:31:40 IST 2019

Linux Set Date Command Example

Use the following syntax to set new data and time:

date --set="STRING"

For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:

# date -s "2 OCT 2006 18:00:00"

OR

# date --set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:

# date +%Y%m%d -s "20081128"

Linux Set Time Examples

To set time use the following syntax:
# date +%T -s "10:13:13"

Where,



Use %p locale’s equivalent of either AM or PM, enter:

# date +%T%p -s "6:10:30AM"

# date +%T%p -s "12:10:30PM"



Based on this article.

2019-07-24 14:23:59

Comments

Add a Comment

Login or Register to post a Comment.

Homepage