# ! /Usr/bin/Python
# Coding = UTF-8
Import Datetime
"""
Powerful functions of datetime
Supported from 0001 to 9999
"""
"""
Current Time
Returns a datetime type.
The now method has a parameter TZ to set the time zone type. If the effect is not the same as that of the today method
"""
Now = datetime. datetime. Now ()
# UTC time
Datetime. datetime. utcnow ()
Attrs = [
( " Year " , " Year " ),( ' Month ' , " Month " ),(" Day " , " Day " ),( ' Hour ' , " Hours " ),( ' Minute ' , " Minute " ),( ' Second ' , " Seconds " ),( ' Microsecond ' , " Millisecond " ),(
' Min ' ," Minimum " ),( ' Max ' , " Max " ),
]
For K, V In Attrs:
" Now. % s = % s # % s " % (K, getattr (now, k), V)
"""
Returns a time structure.
"""
Now. timetuple ()
"""
Returns a date type.
Http://www.cnblogs.com/goodspeed/archive/2011/11/07/python_date_time.html
"""
Now. Date ()
"""
Returns a time type.
Http://www.cnblogs.com/goodspeed/archive/2011/11/07/python_date_time.html
"""
Now. Time ()
"""
The current day of the week. Monday is 0, and the week is 6
Note that the method is not an attribute.
"""
Now. weekday ()
"""
The current day of the week. Monday is 1, week is 7
Note that the method is not an attribute.
"""
Now. isoweekday ()
"""
Modify the current time. For example, change it to the 1st day of the current month.
"""
Now. Replace (Day = 1)
Past = datetime. datetime (2010,11, 12,13, 14,15, 16)
"""
Comparison
The returned value is of the timedelta type.
Http://www.cnblogs.com/goodspeed/archive/2011/11/06/python_timedelta.html
"""
Now-past
"""
Convert to string
For detailed rules, see time
Http://www.cnblogs.com/goodspeed/archive/2011/11/06/python_time.html
"""
Strdatetime = now. strftime ( " % Y-% m-% d % H: % m: % s " )
"""
String generation datetime object
"""
Datetime. datetime. strptime (strdatetime, " % Y-% m-% d % H: % m: % s " )