我希望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)