に変換する"29-Apr-2013-15:59:02"
のような文字列をより使いやすいものに変換したいとします。(YYYY-MM-DD-HH:MM:SS)日付時刻を
ダッシュは、スペースやその他の文字で簡単に置き換えることができます。このフォーマットは理想的です:"YYYYMMDD HH:mm:ss (20130429 15:59:02)"
。
編集:
申し訳ありませんが、私は特に別のポストに答えを見ていません。しかし、再び、私は無知なので、解決策を見ていた可能性があり、それを知らなかった。私はこれが働いているが、私はそれを "かなり"とは考えていないだろう。
#29-Apr-2013-15:59:02
import sys, datetime, time
#inDate = sys.argv[1]
inDate = 29-Apr-2013-15:59:02
def getMonth(month):
monthDict = {'Jan':'01','Feb':'02','Mar':'03','Apr':'04','May':'05','Jun':'06','Jul':'07','Aug':'08','Sep':'09','Oct':'10','Nov':'11','Dec':'12'}
for k, v in monthDict.iteritems():
if month == k:
return v
day = inDate[:2]
#print day
month = inDate[3:6]
#print month
year = inDate[7:11]
#print year
time = inDate[-8:]
#print time
newDate = year+getMonth(month)+day
newDateTime = newDate+" "+time
print newDate
print newDateTime
改善の考えはありますか?
あなたは[ 'のstrftime()'と 'のstrptime()'行動]を読みました(http://docs.python.org/2/library/datetime.html#strftime-strptime-behavior)のドキュメントをご覧ください。あなたに役立つ例があります。 –
@Andbdrew - 注意してください:http://meta.stackexchange.com/questions/172758/what-have-you-tried-epidemic – mgilson
可能であれば、その日付文字列をどのように取得しようとしていますか? – cmd