[Tutor] can time.time() be reversed so as to get date?
Dave Angel
davea at ieee.org
Fri Nov 6 21:14:05 CET 2009
Shashwat Anand wrote:
> Problem resolved.
>
> time.ctime(no_of_seconds - 330*60) does it.
> 330*60, because my time-zone is GMT+5:30 and time.ctime() gives the local
> time while I wanted the GMT.
>
> On Fri, Nov 6, 2009 at 10:00 PM, Shashwat Anand <anand.shashwat at gmail.com>wrote:
>
>
>> If I have been given the number of seconds from midnight 1970.01.01 GMT,
>> can I calculate the date, month and time in the following format : 'Fri Nov
>> 6 9:58:16 2009' ?
>>
>>
You need to study the wording on the actual assignment. There's no
timezone conversion needed as stated, since the seconds are given in
GMT, and you want GMT for the final date & time. If you do convert to
local time and back, you risk getting two kinds of errors:
1) the time zone known to the system may differ from the one you
have using the magic number 330, especially when the system changes to
daylight savings time, and you forget to adjust your value.
2) There is an hour of time in the fall or spring (I think it's in
the fall) when a UTC time cannot be unambiguously represented as local
time. So if you convert to local and back, you'll get a different
answer. That's when the clocks get adjusted for daylight savings time.
So if you indeed want to go from epoch seconds GMT to printable time
GMT, use the combination of time.gmtime() and time.asctime().
No further comments, since you haven't posted any code.
DaveA
More information about the Tutor
mailing list