How to change timely-aware data-time objects for local timezone for synchronous non-timezone-aware datetime Are you
My special application uses Django (though, it is actually a normal python question in reality):
import iso8601 ....
date_str = "2010-10-30T17: 21: 12Z" ....
D = Iso8601.parse_date (date_str) foo = app.models.FooModel (the_date = d) foo.save () Due to throwing an error, Django:
Increase ValueError ("MySQL does not support backend timezone-aware database.") What do I need:
D = iso8601.parse_date (Date_str) local_db = SOME_FUNCTION (d ) Foo = Apikmolskfumodel (the_date = local_d) What will be SOME_FUNCTION ? In general, an arbitrary timezone-aware date for a fair (local) date Time to change the time, I use the pytz module and osteomazone to convert to local time, and to replace replaced with datetime To create: [ex] in [76]: In imported pitts [77]: est = pytz.timezone ('US / Eastern') [78]: D. Stimmon (Est) Out [7] 8]: datetime.datetime (2010, 10, 30, 13, 21, 12, tzinfo = & lt; DstTzInfo 'US / Eastern' EDT-1 day, 20:00:00 DST & gt;) [79]: D.Stimemozone (Est) .replace (tzinfo = none) [7 9]: datetime.datetime (2010, 10, 30, 13, 21, 12) But since your The special date time is in the UTC timezone, [65]: D Out [65]: in datetime.datetime (2010, 10, 30, 17, 21, 12, tzinfo = tzutc ()) in [66]: [65] ]: Import Date Time [67]: In Import Calendar [68]: datetime.datetime.fromtimestamp (Calendar. Time GM (d.timetuple ()) is outside [68]: datetime.datetime (2010, 10, 30, 13, 21, 12)
Anyway, At times, meaningful UTC can store datasets in the form of datasets rather than naïve local dataites. In this way, your data is local time an agnostic, and whenever you need it, you only convert to local time or any other time zone, in Unicode, as much as possible to do the work as possible, and only encoding if necessary.
So if you believe that stupid UCS is the best way to datasets, then define what you need to do:
local_d = d.replace (tzinfo = None)
Comments
Post a Comment