Skip to content

Instantly share code, notes, and snippets.

@omsobliga
Last active February 2, 2018 09:48
Show Gist options
  • Save omsobliga/7711f23795340ef60c4a287c1ee89f6a to your computer and use it in GitHub Desktop.
Save omsobliga/7711f23795340ef60c4a287c1ee89f6a to your computer and use it in GitHub Desktop.
import datetime
import time
# timestamp to datetime
ts = int(time.time())
print datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
# datetime to timestamp
print datetime.datetime(2017, 05, 23, 10, 30, 00).strftime('%s')
# today datetime
dt = datetime.date.today()
print datetime.datetime(dt.year, dt.month, dt.day).strftime('%s')
# date list
date_list = [dt + datetime.timedelta(days=x) for x in range(1, 7)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment