【问题标题】:Convert Time in Eastern time zone and print it in formal time format without GMT-4转换东部时区的时间并以没有 GMT-4 的正式时间格式打印
【发布时间】:2020-01-30 09:02:21
【问题描述】:

time_string="1569834192" #以纪元格式。 我想将其转换为“美国/东部”时区。 但我得到的输出如下: 2019-09-30 14:33:12-04:56 我想要准确的时间而不是这个 -04:56

我的代码: time_string="1569834192" print datetime.fromtimestamp(time_string, tz= pytz.timezone('US/Eastern')).strftime("%Y-%m-%d %H:%M:%S")

输出: 2019-09-30 14:33:12-04:56

time_string="1569834192" print datetime.fromtimestamp(time_string, tz= pytz.timezone('US/Eastern')).strftime("%Y-%m-%d %H:%M:%S")

2019-09-30 14:33:12-04:56

【问题讨论】:

    标签: python timezone gmt


    【解决方案1】:

    Python 3 代码:

    import pytz
    
    from datetime import datetime
    
    time_string = 1569834192
    us_western = pytz.timezone('US/Eastern')
    print(datetime.fromtimestamp(time_string, us_western))
    print(datetime.fromtimestamp(time_string, us_western).strftime("%Y-%m-%d %H:%M:%S"))
    

    输出:

    2019-09-30 05:03:12-04:00
    2019-09-30 05:03:12
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-12
      • 1970-01-01
      • 2018-04-13
      • 2012-07-04
      • 1970-01-01
      • 2020-05-03
      • 2018-01-27
      • 1970-01-01
      相关资源
      最近更新 更多