How to Set the Date and Time on Linux

DZone 's Guide to

How to Set the Date and Time on Linux

Just in case anyone needs a refresher in Linux.

· Open Source Zone ·
Free Resource

A quick post for how to set the date and time on Oracle Linux via the date command. This post is more for my own documentation, but hey, it might help others as well. To set a date or time, you have to pass on the information via a formatted String to the date command. I find calling date twice, once for the date and once for the time, the easiest. The +%D format option allows you to pass on the date as YYYY-MM-DD, e.g. 2019-08-01 for the 1st of August 2019. To set the time, I use the +%T format option to pass on the time as HH24:MI:SS, e.g. 22:31:04.

date +%D -s 2019-08-01
date +%T -s 22:31:04


date +%D -s YYYY-MM-DD
date +%T -s HH24:MI:SS

Happy coding!

date ,date and time ,linux ,open source ,oracle linux ,time ,tutorial

Published at DZone with permission of Gerald Venzl , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}