Created
June 8, 2011 15:37
-
-
Save sbp/1014662 to your computer and use it in GitHub Desktop.
Parse date in python ignoring timezone, python 2.4 compatible
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
| #!/usr/bin/env python | |
| import time, calendar, datetime | |
| input = '2011-05-26T16:02:59.199400+00:00' | |
| input = input.split('.', 1)[0] | |
| input = input.split('+', 1)[0] | |
| then = time.strptime(input, '%Y-%m-%dT%H:%M:%S') | |
| then = datetime.datetime.utcfromtimestamp(calendar.timegm(then)) | |
| td = datetime.datetime.utcnow() - then | |
| seconds = td.seconds + td.days * 24 * 3600 | |
| minutes = float(seconds) / 60 | |
| print minutes < 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment