import time
class Date(object):
def __init__(self,year,month,day): # 创建一个构造函数
self.year = year
self.month = month
self.day = day
# 定义一个实例方法
def One(self):
print('现在的日期是{}年{}月{}日'.format(self.year,self.month,self.day))
# 定义一个静态方法
@staticmethod
def now():
t = time.localtime()
print('今天的日期是{}年{}月{}日'.format(t.tm_year,t.tm_mon,t.tm_mday))
@staticmethod
def tomorrow():
t = time.localtime(time.time() + 86400)
print('明天的日期是{}年{}月{}日'.format(t.tm_year,t.tm_mon,t.tm_mday))
# 创建日期的示例
a = Date(2019,12,1)
# 实例方法调用
a.One()
# 静态方法
b = Date.now()
c = Date.tomorrow()
运行结果
现在的日期是2019年12月1日
今天的日期是2019年12月1日
明天的日期是2019年12月2日