Python Forum

Full Version: convert date input to seconds
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all, I am a beginner to python.
 
I am wondering on how to read input from user: 
DAY 3, 09:00 PM
and convert it to seconds?
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.
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)