can time.time() be reversed so as to get date?

View: New views
10 Messages — Rating Filter:   Alert me  

can time.time() be reversed so as to get date?

by Shashwat Anand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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' ?

_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Shashwat Anand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...> 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' ?


_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Timo List :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Shashwat Anand schreef:
> 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' ?
Yes, I think it can be done with the datetime module.

Timo

> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor@...
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>  

_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by vince spicer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Fri, Nov 6, 2009 at 10:30 AM, Shashwat Anand <anand.shashwat@...> 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' ?

_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



Sure,

   you can get datetime from a teimstamp

EX:


from datetime import datetime
import time

now = time.time()

date = datetime.fromtimestamp(now)

print date.strftime("%a %b %d %H:%M:%S %Y")



Vince



_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Dave Angel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...>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@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Luke Paireepinart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Fri, Nov 6, 2009 at 11:37 AM, Shashwat Anand <anand.shashwat@...> 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.

Where do they use time zones that aren't a multiple of an hour?  That must be incredibly confusing.


_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Shashwat Anand :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Off-Topic :

http://en.wikipedia.org/wiki/Time_zone
7 / 33 time zones are not the multiple of hours.

On Sat, Nov 7, 2009 at 3:25 AM, Luke Paireepinart <rabidpoobear@...> wrote:


On Fri, Nov 6, 2009 at 11:37 AM, Shashwat Anand <anand.shashwat@...> 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.

Where do they use time zones that aren't a multiple of an hour?  That must be incredibly confusing.



_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Alan Gauld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Dave Angel" <davea@...> wrote

> 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.  

There are a myriad of problems involved in working with time zones.
I once had an undergraduate student on summer vacation do a study
on it for me and he produced a paper of over 100 pages documenting
something like 30 different issues he had uncovered. Most of those
issues are still valid today some 15 years later.

If you are working in one timezone its not too bad (although that
depends on which one!) but even then there are issues like the
daylight savings switchover - when 1:30am can come after 1:45am!

And if you include local geographical and political factors it
gets impossible. There is somewhere in the Pacific where the same
street has two different timezones and the local government there
have chosen a different date to implement DST from everywhere
else in either of the timezones! I once went on hioliday to a small
European country where they delayed DST by a week because
it would have spoiled the skiing! This was announced on public radio
on the Wednesday before the clocks were due to change! How is a
computer system supposeed to deal with that kind of arbitrary behaviour?!

And finally we represent times using a discrete numbering system
but it is an essentially analog quantity with an arbitrary baseline, so
there are always opportunities for error and inexactitude, especially
with small values.

rant over,

Alan G.

_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Alan Gauld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Luke Paireepinart" <rabidpoobear@...> wrote

> Where do they use time zones that aren't a multiple of an hour?  That
> must
> be incredibly confusing.

Mainly Asia Pacidfic region. In fact I think even in Australia there is a
difference
of 30 minutes between one of the northern states and one in the south.
Lance Hunt, is that still the case?

The scale of the problem is indicated by the fact that there are, I think,
37 different "official" timezones.

But there are also places which switch timezones rather than implement
a DST scheme. And other places with dual political oversight which have
dual timezones based on whichever political power you are aligned to.
I've never been there but I'm told places like railway stations have two
sets of clocks etc...

Alan G.


_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Re: can time.time() be reversed so as to get date?

by Alan Gauld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

"Shashwat Anand" <anand.shashwat@...> wrote

> http://en.wikipedia.org/wiki/Time_zone
> 7 / 33 time zones are not the multiple of hours.

OK, 33 not 37. The 37 may be the total we came up with to include
all the abberations we uncovered!

Alan G.

_______________________________________________
Tutor maillist  -  Tutor@...
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor