Get a timezone aware datetime with the system timezone in Python
How can I get a datetime object that is timezone aware and is in system's timezone?
What I'm trying to do i开发者_开发知识库s to get unix time of the 23:59 of the current day.
For example, if I do
int(time.mktime(
datetime.datetime.now(pytz.timezone("Europe/Moscow"))
.replace(hour=23, minute=59, second=59)
.timetuple()
))
I get 1314305999
; but when I do $ date -d '@1314305999'
in console, I get Fri Aug 26 00:59:59 MSD 2011
, which is 1 hour off (DST, perhaps), even though I have Europe/Moscow
in /etc/timezone
(and the same problem arises if I use such timestamp in PostgreSQL).
And specifying a precise timezone is not really preferable.
精彩评论