Local solar time function from UTC and longitude

后端 未结 5 1784
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 17:50

I\'m wondering if there is a python function/module that calculates the local time after midnight (or local solar time) given the UTC time and longitude? It doesn\'t need to

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 18:30

    For a very simple function & very very approximated local time: Time variation goes from -12h to +12h and longitude goes from -180 to 180. Then:


    import datetime as dt
    
    def localTimeApprox(myDateTime, longitude):
       """Returns local hour approximation"""
       return myDateTime+dt.timedelta(hours=(longitude*12/180))
    

    Sample calling: localTimeApprox(dt.datetime(2014, 7, 9, 20, 00, 00), -75)

    Returns: datetime.datetime(2014, 7, 9, 15, 0)

提交回复
热议问题