Python:如何将UTC时间戳转换为python utc datetime?

时间:2013-11-20 14:02:45

标签: python datetime

  • 我将客户端时间戳记为Wed, 20 Nov 2013 13:53:35 GMT
  • 我想将此转换为python utc时间戳,以便我可以减去它并获得剩余的天数
def get_days_left_in_month(from_date):
        # todo : how to validate if from_date is valid?
        start_day, end_day = Day.get_start_end_days_for_year_and_month(
            from_date.year, from_date.month
        )
        remaining_days = (end_day - from_date).days
        return remaining_days if remaining_days == 0 else remaining_days - 1

如何使用python执行此操作?

1 个答案:

答案 0 :(得分:0)

试试这个

import time
a = "Wed, 20 Nov 2013 13:53:35 GMT"
time.strptime(a, "%a, %d %b %Y %H:%M:%S %Z")

并查看可用格式的here