Localizing Epoch Time with pytz in Python

后端 未结 3 782
我寻月下人不归
我寻月下人不归 2020-12-08 11:12

Im working on converting epoch timestamps to dates in different timezones with pytz. What I am trying to do is create a DateTime object that accepts an Olson database timez

3条回答
  •  渐次进展
    2020-12-08 12:15

    epochdt = datetime.datetime.fromtimestamp(epoch)
    timezone1 = timezone("Timezone/String")
    adjusted_datetime = timezone1.localize(epochdt)
    

    Working from memory, so excuse any syntax errors, but that should get you on the right track.

    EDIT: Missed the part about knowing the hour,etc. Python has great Time/Date Formatting. At pretty much the bottom of that link is the table showing how to pull different attributes from the datetime object.

提交回复
热议问题