書式設定の日付に問題があります。Pythonの書式datetimeの問題
File "c:\Python27\Lib\_strptime.py", line 322, in _strptime
found = format_regex.match(data_string)
これの何が問題なのです。私は例外を取得私の最後の行で
myDate=datetime.datetime.now()
print myDate #2011-02-02 13:54:26.162000
stime = time.mktime(time.strptime(myDate, '%Y-%m-%d %I:%M%S.%f'))
:これは私のコードですか?私は大人のための誕生のランダムな日付を取得しようとしている
import random
import time
def strTimeProp(start, end, format, prop):
"""Get a time at a proportion of a range of two formatted times.
start and end should be strings specifying times formated in the
given format (strftime-style), giving an interval [start, end].
prop specifies how a proportion of the interval to be taken after
start. The returned time will be in the specified format.
"""
stime = time.mktime(time.strptime(start, format))
etime = time.mktime(time.strptime(end, format))
ptime = stime + prop * (etime - stime)
return time.strftime(format, time.localtime(ptime))
def randomDate(start, end, prop):
return strTimeProp(start, end, '%Y-%m-%d %H:%M:%S.%f', prop)
b1=datetime.datetime.now()
print b1
startDate=b1-datetime.timedelta(27375)
print startDate
endDate=b1-datetime.timedelta(6571)
print endDate
randomDate=randomDate(str(startDate), str(endDate), random.random())
:
EDIT をより明確にするために、これは私がstackoverflowの上で見つけるもののミックスである私の全体のコードです。
私はWindows XPを使用しています。
エポックから秒数を取得しようとしていますか? – SilentGhost
@user:私はあなたの許しを請う?だからあなたは何をしようとしているのですか? – SilentGhost
申し訳ありませんが、私はあなたの質問を理解していない:)私は1936-02-21 14:16:18.936000のような古い日付を置くとき、私は範囲外のmktimeの引数を取得します。私はそれが時代に関連していることを読んだが、私の英語はそれを理解するために弱いです:/ – user278618