Skip to content

Instantly share code, notes, and snippets.

@jflopezfernandez
Created May 24, 2023 23:08
Show Gist options
  • Save jflopezfernandez/8567afc2954e7e1e9194a9d1ba934a57 to your computer and use it in GitHub Desktop.
Save jflopezfernandez/8567afc2954e7e1e9194a9d1ba934a57 to your computer and use it in GitHub Desktop.
This bash script outputs a timestamp of the current time useful for time-dependent filenames, logging statements. etc.
#!/usr/bin/bash
#
# This function is meant to be defined or included in a file automatically
# sourced by the shell on startup, such as the ~/.bashrc file.
#
# Once this function is sourced, it can be called like any other bash function,
# and the output looks something like the following.
#
# 2023-05-24-18:03:09.368078818
#
# TODO(jflopez): Print the timestamp using the current locale's timezone.
function timestamp() {
date "+%Y-%m-%d-%H:%M:%S.%N"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment