第五周-第05章节-Python3.5-内置模块详解之time与datetime模块
Posted pcjbk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第五周-第05章节-Python3.5-内置模块详解之time与datetime模块相关的知识,希望对你有一定的参考价值。
# pcj
import time
# print(time.localtime())
# print(time.time())
# #print(help(time)) #获取time的帮助
# #time.sleep(1) #睡几秒
# print(time.gmtime(10000000000)) # convert seconds since Epoch to UTC tuple 标准时间 utc时区
# print(time.localtime()) #convert seconds since Epoch to local time tuple 本地时间 ,里面可以传值 utc+8
x=time.localtime()
# print(x.tm_year) #取出当时的年
# print(time.localtime().tm_year)#取出当时的年
# print(x.tm_mon) #取出月
# print(x.tm_mday) #取时日期
# print(time.mktime(x)) #把一个元组时间,转换为时间戳
# print(time.strftime("%Y-%m-%d %H:%M:%S",x)) #格式化时间
# print(time.strftime("%m"))
print(time.strptime("2019-06-16 11:41:53","%Y-%m-%d %H:%M:%S")) #把格式化的时间转换为元组
print(x.tm_hour,‘:‘,x.tm_min)
print(time.asctime()) # Convert a time tuple to a string, e.g. ‘Sat Jun 06 16:26:11 1998‘.
#When the time tuple is not present, current time as returned by localtime()
#is used.
print(time.ctime()) #Convert a time in seconds since the Epoch to a string in local time.
# This is equivalent to asctime(localtime(seconds)). When the time tuple is
# not present, current time as returned by localtime() is used.
datetime模块
import datetime
print(datetime.datetime.now()) #打印当前时间now()表示当前
print(datetime.datetime.now()+datetime.timedelta(3)) #当音时间三天前
print(datetime.datetime.now()+datetime.timedelta(-3)) #当音时间三天后
print(datetime.datetime.now()+datetime.timedelta(hours=2)) #当音时间2小时后
print(datetime.datetime.now()+datetime.timedelta(minutes=10)) #当音时间10分钟后
以上是关于第五周-第05章节-Python3.5-内置模块详解之time与datetime模块的主要内容,如果未能解决你的问题,请参考以下文章