好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python 时间操作

python 时间操作

Tech Tips

Using the built-in modules  datetime  and  timedelta , you can perform date and time addition/subtraction in  python :

view plain copy to clipboard print ?

from  datetime  import  datetime   from  datetime  import  timedelta      #Add 1 day    print  datetime.now() + timedelta(days= 1 )      #Subtract 60 seconds    print  datetime.now() - timedelta(seconds= 60 )      #Add 2 years    print  datetime.now() + timedelta(days= 730 )      #Other Parameters you can pass in to timedelta:    # days, seconds, microseconds,    # milliseconds, minutes, hours, weeks       #Pass multiple parameters (1 day and 5 minutes)    print  datetime.now() + timedelta(days= 1 ,minutes= 5 )  

Here is a python reference that gives more examples and advanced features:
http://docs.python.org/library/datetime.html

查看更多关于python 时间操作的详细内容...

  阅读:40次