While date
doesn't have a way to select a time zone, datetime
does. You need to create a subclass of tzinfo with the information for your desired time zone:
class UTC(tzinfo):
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return timedelta(0)
For example, the Eastern Standard Time (UTC-5:00, no DST):
class EST(tzinfo):
def utcoffset(self, dt):
return timedelta(hours = -5)
def tzname(self, dt):
return "EST"
def dst(self, dt):
return timedelta(0)
After making a class for your timezone, you would then get the date
you wanted with:
datetime.now(UTC()).date()
(Replace UTC
with your timezone class name)
There is also a library available, pytz, that would make this much easier for you.