Hi all,
I need your help with my code. I want to convert from time.struct_time to a string.
Example:
To this:
If I want to convert from
Here is the code:
Output for
I'd find that the code I wrote which it is too long and it is not necessary. If you can show me an example how I could do this with my current code, that would be great.
I need your help with my code. I want to convert from time.struct_time to a string.
Example:
1 |
time.struct_time(tm_year = 2018 , tm_mon = 2 , tm_mday = 23 , tm_hour = 8 , tm_min = 0 , tm_sec = 0 , tm_wday = 4 , tm_yday = 54 , tm_isdst = - 1 ) |
1 |
22 / 02 / 2018 23 : 08PM |
time.struct_time
to a string
, I would have to use something like this:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
program_start_date = str (row[ 0 ]) program_start_hours = int (program_start_date.hour) program_start_minutes = str (start_time.minute) program_start_days = int (start_time.day) program_start_months = int (start_time.month) program_start_year = str (start_time.year) #program_start_hours = str(program_start_hours) if program_start_minutes = = "0" : program_start_minutes = "00" elif program_start_minutes = = "5" : program_start_minutes = "05" if program_start_hours > = 0 and program_start_hours < = 9 : program_start_hours = str (program_start_hours) program_start_hours = str ( "0" + program_start_hours) if program_start_days > = 0 and program_start_days < = 9 : program_start_days = str (program_start_days) program_start_days = str ( "0" + program_start_days) if program_start_months > = 0 and program_start_months < = 9 : program_start_months = str (program_start_months) program_start_months = str ( "0" + program_start_months) program_start_hours = int (program_start_hours) program_start_days = str (program_start_days) program_start_months = str (program_start_months) program_finished = str (program_stop_minutes) if program_start_hours > = 00 and program_start_hours < = 12 : program_AM_PM = 'AM' else : program_AM_PM = 'PM' program_start_times = str (program_start_hours + ':' + program_start_minutes + program_AM_PM) program_start_time1 = str (program_start_days + "/" + program_start_months + "/" + program_start_year + " " + program_start_times) program_start_time = time.strptime(program_start_time1, '%d/%m/%Y %H:%M%p' ) |
1 2 3 4 5 6 7 |
cur.execute( 'SELECT start_date, stop_date, title, program_id FROM programs WHERE channel=? and program_id != "" LIMIT 10' , [channel]) programs = cur.fetchall() for ind, row in enumerate (programs): program_start_date = str (row[ 0 ]) start_time = time.strptime(program_start_date, '%Y%m%d%H%M%S' ) #program_start_time = time.strptime(start_time, '%d/%m/%Y %H:%M%p') |
program_start_date
:1 |
20180222230800 |