Mar-07-2017, 02:16 AM
Hi all, I am a beginner to python.
I am wondering on how to read input from user:
I am wondering on how to read input from user:
DAY 3, 09:00 PMand convert it to seconds?
convert date input to seconds
|
Mar-07-2017, 02:16 AM
Hi all, I am a beginner to python.
I am wondering on how to read input from user: DAY 3, 09:00 PMand convert it to seconds?
Mar-07-2017, 02:22 AM
In that specific format, or in a more standard datetime format (like '2/25/70 10:14pm')? If that specific format, the re module (with int() and some multiplication) would probably be best. Otherwise I would look at the time module.
In either case, try something, and when (if) it doesn't work we will help you fix it.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures
Mar-24-2017, 04:49 PM
The time module is pretty rad:
>>> import time >>> parsed = time.strptime("DAY 3, 09:00 PM", "DAY %d, %I:%M %p") >>> parsed time.struct_time(tm_year=1900, tm_mon=1, tm_mday=3, tm_hour=21, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=3, tm_isdst=-1) |
|