代码如下:
author = 'damao'
import time
from datetime import date
from datetime import datetime
import calendar
if __name__ == "__main__":
# 获取今天的日期
today = date.today()
print("今天的日期是",today )
print('今天的日期是 {a},{b},{c}'.format(a=today.year,b=today.month,c=today.day))
# 获取今天是星期几
weekday = today.weekday()
print(weekday)
weekdays = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
print("今天是星期",weekdays[weekday])
# 查看现在时间
now = datetime.now()
print("现在时间是",now)
# 构造一个自己的时间
# t = time(hour=12, minute=20, second=30, microsecond=200)
# print("我的构造时间是",t)
# d = datetime(year=2018, month=8, day=8, hour=8, minute=8, second=8)
# print("我的构造时间是",d)
# 格式化日期时间
print("24小时制全格式:",time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time())))
print("12小时制缩写格式:", time.strftime("%Y-%m-%d %I:%M:%S %a", time.localtime()))
# 带a.m. 或 p.m. 标识时间格式 %p print("带a.m或p.m 24小时制全格式:", time.strftime("%Y-%m-%d %H:%M:%S %p %A", time.localtime())) # 把时区也带上看看 %z print("带时区的全格式:", time.strftime("%Y-%m-%d %H:%M:%S %p %A %z", time.localtime())) # 格式乱排下试试 print("随意排格式:", time.strftime("%A %Y-%d-%m %p %H:%M:%S %z", time.localtime()))
print("带a.m或p.m 24小时制全格式:", time.strftime("%Y-%m-%d %H:%M:%S %p %A", time.localtime()))
# 把时区也带上看看 %z
print("带时区的全格式:", time.strftime("%Y-%m-%d %H:%M:%S %p %A %z", time.localtime()))
# 格式乱排下试试
print("随意排格式:", time.strftime("%A %Y-%d-%m %p %H:%M:%S %z", time.localtime()) + "\n\n")
"""日历"""
cal = calendar.month(2018,1) # 获取2018年1月的日历
print(cal)
cal1 = calendar.calendar(2008) # 获取2008年的日历
print(cal1)