Date

From Leo's Notes
Revision as of 20:21, 30 March 2020 by Leo (talk | contribs)
This page was last edited on 30 March 2020, at 20:21.

The date unix utility can set or show the current time.

Setting the Time

You can set the system clock:

# date -s "Mar 30 2020 13:16"

Though, you really should be using NTP instead.

Formatting

date can be formatted using the + argument followed by the format string. For example:

# date +"%T"
11:26:25

Here are some common formats.

Format Output
%T 12:34:56 (ie: HH:MM:SS)
%r 09:30:55 PM (ie: HH:MM:SS XX)
%m-%d-%y 12-02-15 (ie: MM:DD:YY)
%m-%d-%Y 12-02-2015 (ie: MM:DD:YYYY)
%D 12/02/2015 (ie: MM/DD/YYYY)