0

I need some help with my python code, I have a string in the object that I am comparing with the variable that I created to get the 24 hours time. Now I want to converts the time from 24 hours to 12 hours under the if statement.

Here is the strings:

17:56:26 T:4692  NOTICE: 18:00
17:56:26 T:4692  NOTICE: 18:00
17:56:26 T:4692  NOTICE: 18:00
17:56:26 T:4692  NOTICE: 18:00
17:56:26 T:4692  NOTICE: 18:00
17:56:26 T:4692  NOTICE: 18:00

Output:

17:56:26 T:4692  NOTICE: 6:00
17:56:26 T:4692  NOTICE: 6:00
17:56:26 T:4692  NOTICE: 6:00
17:56:26 T:4692  NOTICE: 6:00
17:56:26 T:4692  NOTICE: 6:00
17:56:26 T:4692  NOTICE: 6:00

Here is the code:

get_stop_time = time.strptime(stop_date, '%Y%m%d%H%M%S')
stop_time = time.strftime('%H:%M', get_stop_time)


if start_time <> current_time < stop_time:
    print "stop_time"
    print stop_time

    #NOW LET CONVERTS TIME TIME FROM 24 HOURS TO 12 HOURS FOR THE STOP_TIME

Can you please show me an example how I could converts the time from the 24 hours to 12 hours using the strings?

What I should use to converts it?

  • 1
    `if start_time <> current_time < stop_time:` ... oh God. Please use `!=` to mean "different". `<>` has been deprecated since a lot of time and in fact it's not valid syntax in python3. – Bakuriu Feb 02 '16 at 18:10
  • read doc for [time](https://docs.python.org/2/library/time.html) – furas Feb 02 '16 at 18:10
  • compare `time` objects instead of `string` in `if` – furas Feb 02 '16 at 18:11
  • 1
    @furas How I can use the strings into times to converts it to 12 hours? –  Feb 02 '16 at 18:29
  • use `%I` in `strftime` to print it as 12 hours - it is in doc for `time` – furas Feb 03 '16 at 00:28

0 Answers0