【问题标题】:Date in format of YYYYMMDD rather than YYYY-MM-DD in python日期格式为 YYYYMMDD 而不是 python 中的 YYYY-MM-DD
【发布时间】:2019-03-28 08:56:25
【问题描述】:

我需要移动的文件具有这样的日期模式:20190328。

我的日期时间模块给我的日期是YYYY-MM-DD。我怎样才能得到表格YYYYMMDD的日期?

【问题讨论】:

  • 发布给你的样本2019-03-28
  • print (str.replace("-","")) ??喜欢here

标签: python python-datetime


【解决方案1】:

使用strftime:

import datetime
print(datetime.datetime.now().strftime("%Y%m%d"))

输出:

20190328

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多