相关疑难解决方法(0)

使用毫秒将日期时间格式化为字符串

我希望datetime从日期开始有一个字符串,以毫秒为单位.这段代码对我来说很典型,我很想学会如何缩短它.

from datetime import datetime

timeformatted= str(datetime.utcnow())
semiformatted= timeformatted.replace("-","")
almostformatted= semiformatted.replace(":","")
formatted=almostformatted.replace(".","")
withspacegoaway=formatted.replace(" ","")
formattedstripped=withspacegoaway.strip()
print formattedstripped
Run Code Online (Sandbox Code Playgroud)

python datetime string-formatting

135
推荐指数
6
解决办法
27万
查看次数

标签 统计

datetime ×1

python ×1

string-formatting ×1