I'm calling an API which gives me the sunrise time of specific cities I request.
The issue is that when the sunrise is before 10 am I get it in the format, for example, '9:10 am'
. This messes up my code and I need it in the format '09:10 am'
. I'm using UTC time depending on the location which is why it can give me time in am or pm.
Is there a way to know the length of a string before a specific character, in this case ':'
?
Example string
{"results":{"sunrise":"9:28:40 PM","sunset":"10:16:12 AM","solar_noon":"3:52:26 AM","day_length":"12:47:32","civil_twilight_begin":"9:05:59 PM","civil_twilight_end":"10:38:53 AM","nautical_twilight_begin":"8:39:14 PM","nautical_twilight_end":"11:05:38 AM","astronomical_twilight_begin":"8:12:02 PM","astronomical_twilight_end":"11:32:50 AM"},"status":"OK"}