a question about datetime

1,709 views
Skip to first unread message

贾晓磊

unread,
Jan 9, 2012, 1:03:32 AM1/9/12
to pywebsv...@lists.sourceforge.net, python-...@googlegroups.com
hi, all:

I have some tried as follows. it works perfect.


>>> import datetime
>>> today = datetime.datetime.now()
>>> today+datetime.timedelta(weeks=1)
datetime.datetime(2012, 1, 16, 11, 52, 8, 33220)
>>> today+datetime.timedelta(days=1)
datetime.datetime(2012, 1, 10, 11, 52, 8, 33220)
>>> help(datetime)


when i run this piece of code, it failed.

>>> today+datetime.timedelta(months=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'months' is an invalid keyword argument for this function

I try to read the source code, but find it 

NAME
    datetime - Fast implementation of the datetime type.

FILE
    /usr/lib/python2.6/lib-dynload/datetime.so


In one word, in the method "datetime.timedelta(months=1)", what are the keys in the method?
if i want to know what key can be used in timedelta(), how should i do ?

-- Jia Xiaolei 

Dmitri Cherniak

unread,
Jan 9, 2012, 1:09:55 AM1/9/12
to python-...@googlegroups.com, pywebsv...@lists.sourceforge.net
This isn't related to tornado, so you shouldn't send general python questions like that here.

贾晓磊

unread,
Jan 9, 2012, 1:14:54 AM1/9/12
to python-...@googlegroups.com, pywebsv...@lists.sourceforge.net
sorry for the mis-sending!

then, thanks for the url ypu provided.

In fact, I know how to solve handle the delay about months and year. what i want to know is that in "
>>> import datetime
>>> today = datetime.datetime.now()"

how to achieve it.

sorry again for the interrupting!

-- Jia Xiaolei
--
NAME: 贾晓磊/Jia Xiaolei
MOBILE: 13011292217
QQ: 281304051

Reply all
Reply to author
Forward
0 new messages