Skip to content

Instantly share code, notes, and snippets.

@neoneo40
Last active September 27, 2015 00:08
Show Gist options
  • Save neoneo40/ef29ddcede07bcb20122 to your computer and use it in GitHub Desktop.
Save neoneo40/ef29ddcede07bcb20122 to your computer and use it in GitHub Desktop.
time.time() to strftime in python. %I, %p, %H. http://strftime.org/
time.time()
# 1443311925.874013
datetime.datetime.fromtimestamp(int(time.time()))
# datetime.datetime(2015, 9, 27, 8, 58, 40)
datetime.datetime.fromtimestamp(int(time.time())).strftime('%Y-%m-%d %H:%M:%S')
# '2015-09-27 08:58:57'
datetime.datetime.fromtimestamp(int(time.time())).strftime('%Y-%m-%d %I:%M:%S %p')
# '2015-09-27 08:59:59 AM'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment