From: Martin P. Hellwig on 11 Jan 2010 08:25 Martin P. Hellwig wrote: > W. eWatson wrote: >> Maybe there's a more elegant way to do this. I want to express the >> result of datetime.datetime.now() in fractional hours. >> >> Here's one way. >> >> dt=datetime.datetime.now() >> xtup = dt.timetuple() >> h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6 >> # now is in fractions of an hour > > Here is another (though personally I don't find this more elegant than > yours, perhaps a bit more readable): > > >>> now = datetime.datetime.now() > >>> fractional_hour = int(now.strftime('%H')) + int(now.strftime('%M')) > / 60.0 > Actually my version is overcomplicated: >>> now = datetime.datetime.now() >>> fractional_hour = now.hour + now.minute / 60.0 -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.'
From: W. eWatson on 11 Jan 2010 11:44 Austyn wrote: > Here's an improvement in case you want your code to work outside of > Arizona: > > from time import time, timezone > h = ((time() - timezone) / 3600) % 24 > > On Jan 10, 9:04 pm, Austyn <aus...(a)gmail.com> wrote: >> How about: >> >> import time >> arizona_utc_offset = -7.00 >> h = (time.time() / 3600 + arizona_utc_offset) % 24 >> >> dt.timetuple()[6] is the day of the week; struct tm_time doesn't >> include a sub-second field. >> >> On Jan 10, 10:28 am, "W. eWatson" <wolftra...(a)invalid.com> wrote: >> >> >> >>> Maybe there's a more elegant way to do this. I want to express the >>> result of datetime.datetime.now() in fractional hours. >>> Here's one way. >>> dt=datetime.datetime.now() >>> xtup = dt.timetuple() >>> h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6 >>> # now is in fractions of an hour > There seems to be some controversy about this and other matters of datetime. <http://blog.twinapex.fi/2008/06/30/relativity-of-time-shortcomings-in-python-datetime-and-workaround/>
From: W. eWatson on 11 Jan 2010 19:53 Martin P. Hellwig wrote: > Martin P. Hellwig wrote: >> W. eWatson wrote: >>> Maybe there's a more elegant way to do this. I want to express the >>> result of datetime.datetime.now() in fractional hours. >>> >>> Here's one way. >>> >>> dt=datetime.datetime.now() >>> xtup = dt.timetuple() >>> h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6 >>> # now is in fractions of an hour >> >> Here is another (though personally I don't find this more elegant than >> yours, perhaps a bit more readable): >> >> >>> now = datetime.datetime.now() >> >>> fractional_hour = int(now.strftime('%H')) + >> int(now.strftime('%M')) / 60.0 >> > Actually my version is overcomplicated: > >>> now = datetime.datetime.now() > >>> fractional_hour = now.hour + now.minute / 60.0 > See my post about the datetime controversy about 3-4 posts up from yours.
From: W. eWatson on 11 Jan 2010 19:53 Martin P. Hellwig wrote: > Martin P. Hellwig wrote: >> W. eWatson wrote: >>> Maybe there's a more elegant way to do this. I want to express the >>> result of datetime.datetime.now() in fractional hours. >>> >>> Here's one way. >>> >>> dt=datetime.datetime.now() >>> xtup = dt.timetuple() >>> h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6 >>> # now is in fractions of an hour >> >> Here is another (though personally I don't find this more elegant than >> yours, perhaps a bit more readable): >> >> >>> now = datetime.datetime.now() >> >>> fractional_hour = int(now.strftime('%H')) + >> int(now.strftime('%M')) / 60.0 >> > Actually my version is overcomplicated: > >>> now = datetime.datetime.now() > >>> fractional_hour = now.hour + now.minute / 60.0 > See my post about the datetime controversy about 3-4 posts up from yours.
From: Ben Finney on 11 Jan 2010 20:27 "W. eWatson" <wolftracks(a)invalid.com> writes: > See my post about the datetime controversy about 3-4 posts up from > yours. This forum is distributed, and there's no “up” or “3-4 messages” that is common for all readers. Could you give the Message-ID for that message? -- \ “As we enjoy great advantages from the inventions of others, we | `\ should be glad to serve others by any invention of ours; and | _o__) this we should do freely and generously.” —Benjamin Franklin | Ben Finney
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Something More Elegant Next: How to use list type generated by SWIG? |