Import datetime in advance.
from datetime import datetime
Use replace to force it to 0:00:00 of the day.
datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)
>>> datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)
datetime.datetime(2015, 8, 22, 0, 0)
I will try to correspond to the time zone using pytz
>>> import pytz
>>> tz = pytz.timezone('Asia/Tokyo')
>>> datetime.now(tz).replace(hour=0,minute=0,second=0,microsecond=0)
datetime.datetime(2015, 8, 22, 0, 0, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>)
In addition to the above, January 1st is fine, so it is as follows.
>>> import pytz
>>> tz = pytz.timezone('Asia/Tokyo')
>>> datetime.now(tz).replace(month=1,day=1,hour=0,minute=0,second=0,microsecond=0)
datetime.datetime(2015, 1, 1, 0, 0, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>)
Recommended Posts