【问题标题】:How to add one day to a timestamp in string format? [duplicate]如何将一天添加到字符串格式的时间戳? [复制]
【发布时间】:2023-01-06 21:55:12
【问题描述】:

我在 python 中有这个字符串值:

string_timestamp = '2023-01-03T00:00:00.000+0000'

如何向这个时间戳添加一天,结果是“2023-01-04T00:00:00.000+0000”?

【问题讨论】:

    标签: python timestamp


    【解决方案1】:

    是这样的:

    from datetime import datetime, timedelta
    
    timestamp = datetime.fromisoformat(string_timestamp)
    
    timestamp += timedelta(days=1)
    
    result = timestamp.strftime('%Y-%m-%dT%H:%M:%S.%f%z')
    
    print(result)  # Output: '2023-01-04T00:00:00.000000+0000'
    

    【讨论】:

      猜你喜欢
      • 2021-12-28
      • 2021-02-22
      • 2018-07-02
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多