用python打印本地日期和时间
我需要以这种精确的字符串格式打印实时本地时间:“用python打印本地日期和时间,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,我需要以这种精确的字符串格式打印实时本地时间:“20190320130348”。(年、月、日、时、分、秒) 我找到了几篇文章,介绍了如何使用时间库打印实时本地时间,但我不知道如何相应地编辑它,以便获得准确的格式。使用: 输出: 20190320111020 print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) # for readability 编辑: 20190320111020 print(strftime("%Y-%m-%d %H:%M:%S
20190320130348
”。(年、月、日、时、分、秒)
我找到了几篇文章,介绍了如何使用时间库打印实时本地时间,但我不知道如何相应地编辑它,以便获得准确的格式。使用:
输出:
20190320111020
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) # for readability
编辑:
20190320111020
print(strftime("%Y-%m-%d %H:%M:%S", gmtime())) # for readability
您可以使用datetime
:
from datetime import datetime
print(datetime.now().strftime('%Y%m%d%H%M%S'))
您可以使用datetime
#import module
import datetime
#get current date and time as a string
now = str(datetime.datetime.now)
#replace what ever you need
now = now.replace("-","").replace(" ","").replace(":","").replace(".","")
e、 g:
打印出:
2019-03-20 13:15:56.469000
操作后:
20190320131556469000
可能重复的