ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] can time.time() be reversed so as to get date?
by Dave Angel other posts by this author
Nov 6 2009 12:16PM messages near this date
Re: [Tutor] can time.time() be reversed so as to get date? | Re: [Tutor] Change a text string from a list and change it into an integer number.(WinXP/py2.6.2/Beginner)
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@[...].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
_______________________________________________
Tutor maillist  -  Tutor@[...].org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Thread:
Shashwat Anand
Vince Spicer
Alan Gauld
Alan Gauld
Alan Gauld
Timo
Shashwat Anand
Luke Paireepinart
Shashwat Anand
Dave Angel

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved