December 19th, 2004, 01:21 PM
Get Current Time
How do I get the exact current time in Python? I need these for my bot to recognize who is spamming in channels and who is not. (FloodBots in case you know that I'm talking about)Also while Im at it I have another question. VB6 needs a DataArrival when using the winsock control, in Python does socket module need anything of this type?
December 19th, 2004, 05:00 PM
Originally Posted by †Yegg†
exact current time as in? localtime?
Check out the time module, it got several options,
Your second question I can't answer as I dont know VB how sockets are used there. The best way to learn sockets in python is to read and test some examples..
>>> import time
['__doc__', '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname']
'Sun Dec 19 22:51:41 2004'
this is a good starting point(using UDP sockets): http://www.evolt.org/article/Socket_Programming_in_Python/17/60276/
December 19th, 2004, 05:01 PM
for your first question
in my opinion, store time in float format e.g time.time(), and do the conversion later, this would be more precise
time.time() #returns a float
#note 0 is 2:00AM 1 Jan 1970
#returns a list of 9 items of the following format
#[Year, Month, Year, Hour. Minute, Second, Day of week, Daylight Savings (True or False) ]
#takes a list of 9 items in the time.localtime() format
#and returns a number
#takes a number and returns a string, defualt is current time
January 6th, 2005, 10:09 PM
currTime = time.strftime("%H:%M:%S", time.localtime(time.time()))