Last active
December 20, 2015 20:59
-
-
Save andrewebdev/6194588 to your computer and use it in GitHub Desktop.
Django: time conversion to drop the miliseconds
This file contains 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
def format_date_for_sforce(timestamp): | |
""" | |
Returns a datetime formatted as 2012-02-15T19:03:32-0800 | |
""" | |
if not timestamp: | |
return timestamp | |
total_seconds = timestamp.utcoffset().total_seconds() | |
minutes, seconds = divmod(total_seconds, 60) | |
hours, minutes = divmod(minutes, 60) | |
time_string = timestamp.strftime("%Y-%m-%dT%H:%M:%S%%+03d%%02d") | |
return time_string % (hours, minutes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment