문제

Curently I am using this:

from datetime import datetime
startDate = datetime.strptime('03.12.2004', '%d.%m.%Y')

Is there some simpler/Pythonic way ?

도움이 되었습니까?

해결책

You can use the following to initialize a datetime object instead of using the string above:

datetime.datetime(2004, 12, 3)

다른 팁

Not that shorter is better, but I find it easier to read if you're going to have a lot of lines creating datetimes, of course assuming 'dt' doesn't clash with anything else in your code.

from datetime import datetime as dt

start = dt(2004, 12, 3)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top