[英]How to get current time in python and break up into year, month, day, hour, minute?
[英]python date time get the current time but with seconds and hour and minute
我能夠獲得當前時間,如下所示:
import datetime
str(datetime.date.today().strftime("%Y-%m-%d"))
那個打印
2016-06-26
但我需要添加分鍾、秒和小時
我在互聯網上搜索,人們建議使用這個:
str(datetime.date.today().strftime("%Y-%m-%d %H:%M"));
但實際上%H:%M
總是返回00:00
你能幫忙嗎?
datetime.date
只處理日期,你需要使用datetime.datetime
。
您正在使用不包含任何時間的 datetime.date 對象。
你需要使用'datetime.datetime.now()'
試試這個:將返回一個帶有小時、分鍾和秒的字符串
datetime.datetime.now()..strftime("%Y-%m-%d %H:%M:%S")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.