Date
From Leo's Notes
This page was last edited on 11 June 2020, at 20:09.
The date unix utility can set or show the current time.
Cheat Sheet
The date utility can be used with a custom format specified by as +<FORMAT>.
Here are some commonly used formats.
| Format | Output | Comment |
|---|---|---|
| date | Thu Jun 11 14:00:47 MDT 2020 | default output |
| date +%T | 12:34:56 | HH:MM:SS |
| date +%r | 09:30:55 PM | HH:MM:SS AA |
| date +%m-%d-%y | 12-02-15 | MM:DD:YY |
| date +%m-%d-%Y | 12-02-2015 | MM:DD:YYYY |
| date +%D | 12/02/2015 | MM/DD/YYYY |
Date can also parse a timestamp given with --date argument.
$ date --date="Dec 25, 1889" +%m-%d-%y
12-25-89
## Convert to unix timestamp
$ date --date="Dec 25, 1889" +%s
-2525099168
## Or to nanoseconds (9 0's)
$ date --date="Dec 25, 1998" +%s000000000
914569200000000000
Setting the Time
You can set the system clock:
# date -s "Mar 30 2020 13:16"
Though, you really should be using NTP instead.