0

The Sunrise-Sunset API returns sunrise/sunset times in UTC string format. How can I convert this time into my local time zone (PST) and store the hours, minutes, and seconds into variables easily and concisely in python?

  {
      "results":
      {
        "sunrise":"2015-05-21T05:05:35+00:00",
        "sunset":"2015-05-21T19:22:59+00:00",
        "solar_noon":"2015-05-21T12:14:17+00:00",
      },
       "status":"OK"
    }
FObersteiner
  • 16,957
  • 5
  • 24
  • 56
  • to go from UTC to US/Pacific, you could use `datetime.fromisoformat("2015-05-21T05:05:35+00:00").astimezone(ZoneInfo("America/Los_Angeles"))`, with imports `from datetime import datetime` and `from zoneinfo import ZoneInfo` (Python 3.9). – FObersteiner Apr 14 '22 at 08:17

0 Answers0