-3
我的字符串是:Nov 05 2016 01:30:00PM
我需要刪除前導月和小時 0輸出應該像Nov 5 2016 1:30:00PM
在Windows中刪除在一個月前導零的日期蟒蛇
添加%和字母之間的連字符,你不能刪除前導零窗口..所以我不能使用該選項。
import time
from_date="2016-10-02T01:45:00"
conv=time.strptime(from_date,"%Y-%m-%dT%H:%M:%S")
conDateTime = time.strftime("%b %d %Y %I:%M:%S%p",conv)
print conDateTime
day = time.strftime("%d",conv).lstrip('0')
hour = time.strftime("%H",conv).lstrip('0')
conDateTime = conDateTime.replace(time.strftime("%d",conv), day)
conDateTime = conDateTime.replace(time.strftime("%I",conv), hour)
print conDateTime
出放:10月2日216上午01點45分00秒 它消除年份和月份的0
conDateTime = conDateTime.replace(time.strftime("%d",conDateTime), day)
給出以下錯誤類型錯誤:參數必須是9項順序,不str的
加入你試過到目前爲止 –
試試這個代碼是什麼,請給予更詳細的'打印工作的一種方式格式(conv.tm_hour)+ time.strftime(「:%M:%S%p」,轉換) 「time.strftime(」%b%e%Y「,conv)+」{0:d} – Serenity