Skip to content

Instantly share code, notes, and snippets.

@wfwei
Last active October 12, 2015 06:47
Show Gist options
  • Save wfwei/3986654 to your computer and use it in GitHub Desktop.
Save wfwei/3986654 to your computer and use it in GitHub Desktop.
python datetime from datetime to timestamp
from datetime import datetime
import time
now = datetime.now()
u = str(long(time.mktime(now.timetuple())))
@wfwei
Copy link
Author

wfwei commented Nov 22, 2012

import datetime
print(datetime.datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d %H:%M:%S'))

@wfwei
Copy link
Author

wfwei commented Dec 3, 2012

datetime.now().strftime("%Y-%m-%d %H:%M:%S")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment