Skip to content

Instantly share code, notes, and snippets.

@dmyersturnbull
Last active August 1, 2016 18:16
Show Gist options
  • Save dmyersturnbull/e83bea03e76c8ffa2ba21b21bb8859f4 to your computer and use it in GitHub Desktop.
Save dmyersturnbull/e83bea03e76c8ffa2ba21b21bb8859f4 to your computer and use it in GitHub Desktop.
YYYY-mm-dd_HH-MM-SS timestamp.
import datetime
def format_time(time: datetime.datetime) -> str:
"""Standard timestamp format. Ex: 2016-05-02_22_35_56."""
return time.strftime("%Y-%m-%d_%H-%M-%S")
def timestamp() -> str:
"""Standard timestamp of time now. Ex: 2016-05-02_22_35_56."""
return format_time(datetime.datetime.now())
def timestamp_path(path: str) -> str:
"""Standard way to label a file path with a timestamp."""
return "{}-{}".format(path, timestamp())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment