0
sunrise = tt.strftime('%I:%M %p', tt.gmtime(json_data['sys']['sunrise'] - 21600))
sunset = tt.strftime('%H:%M %p', tt.gmtime(json_data['sys']['sunset'] - 21600))

Results:

Sunrise is: 05:45 PM
Sunset is: 07:20 AM

But sunrise is am and sunset is pm. Please tell me what's the error.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

Possible duplicate of How can I account for period (AM/PM) using strftime?.

As stated in the answers to that question, when using the directive %p, you should use the 12-hour format %I instead of the 24-hour format %H to output the equivalent AM or PM for your locale.

You can also try reading the docs for strftime() here,

appauldev
  • 21
  • 4