作者:心若在梦就在_2012 | 来源:互联网 | 2023-08-01 15:16
#pcjimporttime#print(time.localtime())#print(time.time())##print(help(time))#获取time的帮助##tim
# 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分钟后