#! /usr/bin/python
# coding=utf-8
from datetime import datetime,date,time
"""
date类型顾名思义就是只表示日期,而time只表示time
"""
today = date.today()
attrs = [
("year","年"),( 'month',"月"),( 'day',"日")
]
for k,v in attrs:
"today.%s = %s #%s" % (k,getattr(today, k),v)
#星期几。同datetime规则一样
today.isoweekday()
today.weekday()
#返回一个time结构,当然也就没有时间信息
today.timetuple()
#修改。同datetime规则一样
today.replace(month=1)
#转成字符串,不可以转回
today.strftime("%Y-%m-%d")
now = time(12,13,14)
attrs = [
("hour","小时"),( 'minute',"分"),( 'second',"秒"),("microsecond","毫秒")
]
for k,v in attrs:
"now.%s = %s #%s" % (k,getattr(now, k),v)
#修改。同datetime规则一样
now.replace(minute=1)
#转成字符串,不可以转回
now.strftime("%H:%M:%S")
#date和time合并成datetime
print datetime.combine(today, now)