Time zone field in isoformat

后端 未结 3 1384
死守一世寂寞
死守一世寂寞 2020-11-29 07:23

I have a timestamp that is supposed to be in EST:

2014-10-06T18:06:40-04:56

I understand this first part: 2014-10-06T18:06:40,

3条回答
  •  误落风尘
    2020-11-29 08:13

    I suggest looking at arrow. The above answers worked but make the code really confusing to follow. Arrow lets you do this simply using:

    In [82]: start_time = arrow.get(2014, 10, 6, 18).to('US/Eastern')
    In [83]: end_time = start_time.shift(seconds=400)
    In [84]: start_time
    Out[84]: 
    In [85]: end_time
    Out[85]: 
    

    You can retrieve the datetime objects by using

    In [86]: start_time.datetime
    Out[86]: datetime.datetime(2014, 10, 6, 14, 0, tzinfo=tzfile('/usr/share/zoneinfo/US/Eastern'))
    

提交回复
热议问题