106 lines
3.5 KiB
Python
106 lines
3.5 KiB
Python
import datetime
|
||
import time
|
||
|
||
# # 今天的日期
|
||
# print("今天的日期是:", datetime.date.today())
|
||
#
|
||
# print("使用时间戳创建日期", datetime.date.fromtimestamp(1234567896))
|
||
#
|
||
# print("使用公历序数创建的日期:", datetime.date.fromordinal(1))
|
||
#
|
||
# today = datetime.date(year=2020,month=8,day=31) # 使用参数创建日期
|
||
#
|
||
# print('date对象的年份:', today.year)
|
||
#
|
||
# print('date对象的月份:', today.month)
|
||
#
|
||
# print('date对象的日:', today.day)
|
||
#
|
||
# print("date对象的struct_time结构为:",today.timetuple())
|
||
#
|
||
# print("返回当前公历日期的序数:",today.toordinal()) # 与fromordinal函数作用相反
|
||
#
|
||
# print("当前日期为星期(其中:周一对应0):{}".format(today.weekday()))
|
||
#
|
||
# print("当前日期为星期(其中:周一对应1):{}".format(today.isoweekday()))
|
||
#
|
||
# print("当前日期的年份、第几周、周几(其中返回为元组):",today.isocalendar())
|
||
#
|
||
# print("以ISO 8601格式‘YYYY-MM-DD’返回date的字符串形式:",today.isoformat())
|
||
#
|
||
# print("返回一个表示日期的字符串(其格式如:Mon Aug 31 00:00:00 2020):",today.ctime())
|
||
#
|
||
# print("指定格式为:",today.strftime("%Y/%m/%d"))
|
||
#
|
||
# print("替换后的日期为:",today.replace(2019,9,29))
|
||
#
|
||
# create_time = datetime.time(hour=11,minute=18,second=31) # 使用参数创建日期
|
||
#
|
||
# print('create_time对象的小时为:', create_time.hour)
|
||
#
|
||
# print('create_time对象的分钟为:', create_time.minute)
|
||
#
|
||
# print('create_time对象的秒数为:', create_time.second)
|
||
#
|
||
# print("返回create_time的字符串形式:",create_time.isoformat())
|
||
#
|
||
# print("指定格式为:",create_time.strftime("%H/%M/%S"))
|
||
#
|
||
# print("替换后的时间为:",create_time.replace(20,9,29))
|
||
#
|
||
# print("现在的时间是:",datetime.datetime.today())
|
||
#
|
||
# print("返回现在的时间是:",datetime.datetime.now())
|
||
#
|
||
# print("当前UTC日期和时间是:",datetime.datetime.utcnow())
|
||
#
|
||
# print("对应时间戳的日期和时间是:",datetime.datetime.fromtimestamp(1234567896))
|
||
#
|
||
# print("对应UTC时间戳的日期和时间是:",datetime.datetime.utcfromtimestamp(1234567896))
|
||
#
|
||
# print("公历序列对应的日期和时间是:",datetime.datetime.fromordinal(1))
|
||
#
|
||
# print("日期和时间的合体为:",datetime.datetime.combine(datetime.date(2020, 8, 31), datetime.time(12, 12, 12)))
|
||
#
|
||
# now = datetime.datetime(2020,8,31,12,10,10)
|
||
#
|
||
# print("年为:",now.year)
|
||
#
|
||
# print("月为:",now.month)
|
||
#
|
||
# print("日为:",now.day)
|
||
#
|
||
# print("小时为:",now.hour)
|
||
#
|
||
# print("分钟为:",now.minute)
|
||
#
|
||
# print("秒数为:",now.second)
|
||
#
|
||
# print('当前日期为:', now.date() )
|
||
#
|
||
# print('当前时间:', now.time() )
|
||
#
|
||
# print("返回struct_time为",now.timetuple()) # 和date一样
|
||
#
|
||
# print("返回UTC的struct_time为",now.utctimetuple())
|
||
#
|
||
# print("返回的公历序列数为:",now.toordinal()) # 和date一样
|
||
#
|
||
# print("返回标准日期格式为:",now.isoformat()) # 和date一样
|
||
#
|
||
# print("返回的周几(1表示周一):",now.isoweekday()) # 和date一样
|
||
#
|
||
# print("返回的周几(0表示周一):",now.weekday()) # 和date一样
|
||
#
|
||
# print("now.isocalendar():", now.isocalendar()) # 和date一样
|
||
#
|
||
# print("now.ctime():",now.ctime()) # 和date一样
|
||
#
|
||
# print("格式化时间为:",now.strftime('%Y/%m/%d %H:%M:%S')) # 把日期按照format指定的格式进行格式化
|
||
#
|
||
# print(datetime.datetime.strptime("2020/12/29 8:8:00",'%Y/%m/%d %H:%M:%S'))
|
||
|
||
current_time = 1577761708
|
||
date_time = datetime.datetime.fromtimestamp(current_time)
|
||
print(date_time)
|
||
print(time.localtime()) |