Last active
May 3, 2016 21:04
-
-
Save fernandojunior/13196c844ce084004455 to your computer and use it in GitHub Desktop.
timestamp to datetime in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> import datetime | |
| >>> matchCreation = 1421845413033 # timestamp em milisegundos | |
| >>> datetime.datetime.fromtimestamp(matchCreation / 1e3).strftime('%Y-%m-%d %H:%M:%S') | |
| '2015-01-21 10:03:33' | |
| >>> import datetime, time | |
| >>> t = datetime.datetime(2015, 12, 10, 1, 51, 16) | |
| >>> timestamp = time.mktime(t.timetuple()) # converve datetime para timestamp em segundos ... | |
| >>> timestamp | |
| 1449723076.0 | |
| >>> datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S') # converte timestamp para datetime | |
| '2015-12-10 01:51:16' | |
| http://stackoverflow.com/questions/9744775/how-to-convert-integer-timestamp-to-python-datetime | |
| http://stackoverflow.com/questions/7852855/how-to-convert-a-python-datetime-object-to-seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment