diff --git a/README.md b/README.md index 4023f9a..3b892f3 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://tinyletter.com/jbranchaud). -_1020 TILs and counting..._ +_1021 TILs and counting..._ --- @@ -888,6 +888,7 @@ _1020 TILs and counting..._ ### Shell - [Check If The First Argument Is Given](shell/check-if-the-first-argument-is-given.md) +- [Format And Print The Current Date And Time](shell/format-and-print-the-current-date-and-time.md) ### tmux diff --git a/shell/format-and-print-the-current-date-and-time.md b/shell/format-and-print-the-current-date-and-time.md new file mode 100644 index 0000000..98b077a --- /dev/null +++ b/shell/format-and-print-the-current-date-and-time.md @@ -0,0 +1,28 @@ +# Format And Print The Current Date And Time + +If I run the `date` command from the terminal, I get output like the following: + +```bash +$ date +Fri Jan 22 13:45:44 CST 2021 +``` + +If I want to format the date output different, perhaps for inclusion in a shell +script, I can do something like this: + +```bash +$ date +"%Y/%m/%d %H:%M:%S" +2021/01/22 13:47:55 +``` + +Then I can incorporate that in a script like this: + +```bash +now() { + echo "Today: $(date +'%Y/%m/%d %H:%M:%S')" +} +``` + +This +[page](https://www.tutorialkart.com/bash-shell-scripting/bash-date-format-options-examples/) +includes some examples and a page of formatting options.