Skip to content

Instantly share code, notes, and snippets.

@Mlawrence95
Created March 31, 2020 22:18
Show Gist options
  • Save Mlawrence95/7646efcbd0422e7573c5387995066e59 to your computer and use it in GitHub Desktop.
Save Mlawrence95/7646efcbd0422e7573c5387995066e59 to your computer and use it in GitHub Desktop.
Use python's time library to print the date as a single string in m/d/y format, GMT. Useful for adding timestamps to filenames
import time
def get_timestamp():
"""
Print the date in m/d/y format, GMT
>>> get_timestamp()
'3_31_2020'
"""
t = time.gmtime()
month, day, year = str(t.tm_mon), str(t.tm_mday), str(t.tm_year)
return "_".join([month, day, year])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment