Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old November 10th, 2003, 04:19 PM
penngray penngray is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 38 penngray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 31 sec
Reputation Power: 5
Time problem question

Maybe Im just exhausted but I cant think this one through.

I need to do the following.

1 if time.time() + (x hours) is between midnight and 9 am.

and

I need to know how many hours the difference is between 9 am tommorrow and the current time.


Im pretty new to python and I cant solve this one.

thanks
penn

Reply With Quote
  #2  
Old November 10th, 2003, 05:04 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Mmmm, i don't know of the top of my head although i can't imagin its going to be too hard.. you have too module choices here from what i can see time and datetime.

Oh, can you give me some more details?

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old November 10th, 2003, 05:40 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Sometimes i surprise myself, this was so much easier than i'd imagined. Heres the code:

Code:
#!/usr/bin/env python

import time

#this is only a very simple example.. 'hour' is the number of hours
#too be added to the current time (in seconds) where 3600 is the
#number of seconds in one hour! 'then' is the hour stored within
#the tuple returned by time.localtime().

hour = 5
then = time.localtime(time.time() + 3600 * hour)[3]

#if 'then' is less than 9 then it must be between midnight (0) and
#9am (9).

if then < 9:
	print then, 'is between midnight and 9am..'
else:
	print then, 'is just too late..'


if you have any questions ask away..

Mark.

Reply With Quote
  #4  
Old November 10th, 2003, 06:09 PM
penngray penngray is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 38 penngray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 31 sec
Reputation Power: 5
thank you for the quick response and I think you even more for the code. I didnt expect that.

I have been looking through the directory for the time.py but I cant find it??

I already have "import time" in my program but I wanted to read through the complete time.py to find out what is available. Where would it be becuase its not in the root python2.2.3 directory.

again thanks!

Reply With Quote
  #5  
Old November 10th, 2003, 06:31 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
chances are that the time module is written in C/C++, this would of course mean a different extension.. it also means that you wont be able to look though the source-code for this module

If you want a list of all the available objects in an object you can try something like this:

>>> import time
>>> dir(time)
['__doc__', '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname']
>>>

Note: this also works with classes etc.

Mark.

Reply With Quote
  #6  
Old November 10th, 2003, 06:45 PM
penngray penngray is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 38 penngray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 31 sec
Reputation Power: 5
thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Time problem question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway