python - Datetime - Strftime and Strptime
问题描述
Date = datetime.datetime.today().strftime("%d %B %Y")
x = datetime.datetime.strptime(Date , "%d %B %Y")
returns:
2018-05-09 00:00:00
instead of: 9 May 2018, what am I doing wrong? Essentially I am trying to get the non zero padded version of strftime for which I searched around and I read that the way to go about it is strptime.
解决方案
一个可能的解决方案是使用str.lstrip
前任:
import datetime
Date = datetime.datetime.today().strftime("%d %B %Y")
print(Date.lstrip("0"))
输出:
9 May 2018
推荐阅读
- netbeans - 未设置 X11 显示变量,使用 MobaXTerm 从命令行安装 netbeans
- android - 从 Google 地图向带有地理信息的 Android 应用发送 Intent
- python - 当函数需要数据框行python时使用apply()
- git - 确保生成的尚未签入的文件在 git sync 后不会重建
- scala - Scala .init 方法示例
- c# - Python.net 不适用于带有命名参数的 python => .NET?
- amazon-s3 - 有没有人设法使用 SAS Enterprise guide v6.1 连接到 s3?
- azure - Azure Runbook 无法修改 Azure AD 应用程序
- css - 带有列填充的 CSS 列表
- javascript - PostgreSQL docker-compose down 后使用的端口不能再次使用