From 951b7f953f335ae89aeddaf64e911fd88775f551 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 2 Jun 2023 11:39:07 -0500 Subject: [PATCH] Add Print The Current Date In Human-Readable Format as a Unix TIL --- README.md | 3 ++- ...e-current-date-in-human-readable-format.md | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 unix/print-the-current-date-in-human-readable-format.md diff --git a/README.md b/README.md index b01d1e1..0b351a0 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1307 TILs and counting..._ +_1308 TILs and counting..._ --- @@ -1298,6 +1298,7 @@ _1307 TILs and counting..._ - [PID Of The Current Shell](unix/pid-of-the-current-shell.md) - [Print A Range Of Lines For A File With Bat](unix/print-a-range-of-lines-for-a-file-with-bat.md) - [Print Out Files In Reverse](unix/print-out-files-in-reverse.md) +- [Print The Current Date In Human-Readable Format](unix/print-the-current-date-in-human-readable-format.md) - [Provide A Fallback Value For Unset Parameter](unix/provide-a-fallback-value-for-unset-parameter.md) - [Remove A Directory Called `-p`](unix/remove-a-directory-called-dash-p.md) - [Repeat Yourself](unix/repeat-yourself.md) diff --git a/unix/print-the-current-date-in-human-readable-format.md b/unix/print-the-current-date-in-human-readable-format.md new file mode 100644 index 0000000..73114f8 --- /dev/null +++ b/unix/print-the-current-date-in-human-readable-format.md @@ -0,0 +1,26 @@ +# Print The Current Date In Human-Readable Format + +The `date` utility by default does a good job of displaying the current date in +a human-readable format. + +```bash +❯ date +Fri Jun 2 11:30:03 CDT 2023 +``` + +It has some additional info like the time and timezone. + +If I just want to see the date with the day of the week, I can call `date` with +a format string that uses special identifiers for each part of the date. This +gives me control over exactly how it is displayed. For example, the following +format string works for my purposes. + +```bash +❯ date '+%A %B %d, %Y' +Friday June 02, 2023 +``` + +The `+` indicates that it is a user-specified format string and the rest of the +special identifiers are defined by `strftime`. + +See `man date` and `man strftime` for more details.