Created
November 10, 2012 15:09
-
-
Save maniartech/4051358 to your computer and use it in GitHub Desktop.
Contains useful datetime related functions...
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
import datetime as dt | |
from datetime import datetime | |
import pytz | |
def local_datetime(timezone = 'Asia/Calcutta'): | |
""" | |
Returns the local time based on provided timezone. | |
""" | |
utc = datetime.utcnow() | |
tz = pytz.timezone(timezone) | |
return tz.fromutc (utc) | |
def add_days(date_time, days): | |
""" | |
Add the new date after adding specified numbers of days to provided date_time. | |
""" | |
return date_time + dt.timedelta(days) | |
def add_months(date_time, months): | |
""" | |
Add the new date after adding specified numbers of months to provided date_time. | |
""" | |
return date_time + dt.timedelta(months*365/12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment