【问题标题】:Python: How can I convert a UTC timestamp into python utc datetime? [duplicate]Python:如何将 UTC 时间戳转换为 python UTC 日期时间? [复制]
【发布时间】:2013-12-04 13:37:59
【问题描述】:
  • 我得到客户端时间戳为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 做到这一点?

【问题讨论】:

标签: python datetime


【解决方案1】:

试试这个

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

查看here 了解可用格式。

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 2017-04-27
    • 1970-01-01
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    相关资源
    最近更新 更多