python - How to get an isoformat datetime string including the default timezone? -
Let me prepare a time string that matches the ISO format yyyy-mm-ddThh: mm: ss.ssssss Will be -ZO: Northeast
. now ()
and utcnow ()
class methods are almost what I want to do.
& gt; & Gt; & Gt; Import Date Time & gt; & Gt; & Gt; # Time adjusted for current timezone & gt; & Gt; & Gt; Datetime.datetime.now (). Isoformat () '2010-08-03T03: 00: 00.000000' & gt; & Gt; & Gt; #unadjusted UTC Time & gt; & Gt; & Gt; Datetime.datetime.utcnow (). Isoformat () '2010-08-03T10: 00: 00.000000' & gt; & Gt; & Gt; & Gt; & Gt; & Gt; #how can I do this? & Gt; & Gt; & Gt; Datetime.datetime.magic () '2010-08-03T10: 00: 00.000000-07: 00' '
Note something like the following example I am in Eastern Australia (UTC + 10 hours)
& gt; & Gt; & Gt; Import Date Time & gt; & Gt; & Gt; Dtnow = datetime.datetime.now (); Dtutcnow = datetime.datetime.utcnow () & gt; & Gt; & Gt; Dtnow datetime.datetime (2010, 8, 4, 9, 33, 9, 890000) & gt; & Gt; & Gt; Dtutcnow datetime.datetime (2010, 8, 3, 23, 33, 9, 890000) & gt; & Gt; & Gt; Delta = Doton - DTUTICONO & gt; & Gt; & Gt; Delta Datetime Timedelata (0, 36000)> gt; & Gt; & Gt; HH, MM = DVMOD (Delta Dais * 24 * 60 * 60+ Delta.Second +30) // 60, 60)> gt; & Gt; HH, mm (10, 0)> gt; & Gt; & Gt; "% S% + 02d:% 02d"% (dtnow.isoformat (), hh, mm) '2010-08-040 9: 33: 09.890000 + 10: 00' & gt; & Gt; & Gt;
Comments
Post a Comment