Hi all,
So a lot of digging on doing this and still not a fabulous solution:
import time
# this takes the last_modified_d ate naive datetime, converts it to a
# UTC timetuple, converts that to a timestamp (seconds since the
# epoch), subtracts the timezone offset (in seconds), and then
converts
# that back into a timetuple... Must be an easier way...
mytime = time.localtime( time.mktime(las t_modified_date .utctimetuple() )
- time.timezone)
lm_date_str = time.strftime(" %m/%d/%Y %I:%M %p %Z", mytime)
last_modified_d ate is a naive datetime.dateti me object
A previous version gave me something like:
mytime =
datetime.dateti me.fromtimestam p(time.mktime(l ast_modified_da te.utctimetuple ())
- time.timezone)
lm_date_str = mytime.strftime ("%m/%d/%Y %I:%M %p %Z")
But this gave me no timezone since the datetime object is still
naive. And I'm going from a datetime to a timetuple to a timestamp
back to a datetime...
All this seems like a lot of monkeying around to do something that
should be simple -- is there a simple way to do this without requiring
some other module?
thx
Matt
So a lot of digging on doing this and still not a fabulous solution:
import time
# this takes the last_modified_d ate naive datetime, converts it to a
# UTC timetuple, converts that to a timestamp (seconds since the
# epoch), subtracts the timezone offset (in seconds), and then
converts
# that back into a timetuple... Must be an easier way...
mytime = time.localtime( time.mktime(las t_modified_date .utctimetuple() )
- time.timezone)
lm_date_str = time.strftime(" %m/%d/%Y %I:%M %p %Z", mytime)
last_modified_d ate is a naive datetime.dateti me object
A previous version gave me something like:
mytime =
datetime.dateti me.fromtimestam p(time.mktime(l ast_modified_da te.utctimetuple ())
- time.timezone)
lm_date_str = mytime.strftime ("%m/%d/%Y %I:%M %p %Z")
But this gave me no timezone since the datetime object is still
naive. And I'm going from a datetime to a timetuple to a timestamp
back to a datetime...
All this seems like a lot of monkeying around to do something that
should be simple -- is there a simple way to do this without requiring
some other module?
thx
Matt
Comment