Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54244
| From | Michael Schwarz <michi.schwarz@gmail.com> |
|---|---|
| Subject | Re: Is %z broken for return values of time.gmtime()? |
| Date | 2013-09-16 22:55 +0200 |
| References | <3C2755B3-2478-45E1-88F5-9FD961F2B1BD@gmail.com> <1379354161.1707.22675889.2647208B@webmail.messagingengine.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.36.1379364943.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On 2013-W38-1, at 19:56, random832@fastmail.us wrote: > On Mon, Sep 16, 2013, at 9:15, Michael Schwarz wrote: >> According to the documentation of time.gmtime(), it returns a struct_time >> in UTC, but %z is replaced by +0100, which is the UTC offset of my OS’s >> time zone without DST, but DST is currently in effect here (but was not >> at the timestamp passed to gmtime()). > > The struct_time type does not include information about what timezone it > is in. Uhm … Python 3.3 introduced the tm_gmtoff member of struct_time, which contains the offset to UTC. I thought, %z was also introduced in Python 3.3 and so I thought it would use that field. What time zone does it use then? Does it always use the system's time zone? > You can use datetime.datetime (e.g. datetime.datetime.fromtimestamp(40 * > 365 * 86400,datetime.timezone.utc) - the datetime.datetime class has a > strftime method. I do use that, but I was using time.localtime() to convert a POSIX timestamp to a date using the system's timezone and saw that while a struct_time produced by time.localtime() and formatted using time.strftime() shows the correct time zone (+0100 and +0200 here), it does not for a struct_time produced by time.gmtime(). I think that's strange. > You should be aware that %F and %T are not portable and won't work on > windows for example. I’m aware of that, but thanks. I was toying around and just needed to print the rest of the date. Regards Michael
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Is %z broken for return values of time.gmtime()? Michael Schwarz <michi.schwarz@gmail.com> - 2013-09-16 22:55 +0200
csiph-web