【python】取得字符串形式的当前日期时间
代码:
#encoding=utf-8 import datetime d=datetime.datetime.today() dateStr=d.strftime('%Y-%m-%d_%H:%M:%S') print("Current time=",dateStr)
输出:
C:\hy\py>python 04-currentDatetime.py
Current time= 2022-01-25_20:42:17
END
代码:
#encoding=utf-8 import datetime d=datetime.datetime.today() dateStr=d.strftime('%Y-%m-%d_%H:%M:%S') print("Current time=",dateStr)
输出:
C:\hy\py>python 04-currentDatetime.py
Current time= 2022-01-25_20:42:17
END