time模块

时间:2019-06-14
本文章向大家介绍time模块,主要包括time模块使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
import time
# print(time.time())              #返回时间戳
# print(time.localtime())         #返回元组形式 返回当地时间
# print(time.gmtime())            #返回元组形式 返回utc时区
# print(time.timezone)
# print(time.gmtime(1540730812))  #将时间戳转换为元组形式
# x = time.localtime()
# print(x)
# print(time.mktime(x))           #将元组形式转换为时间戳
# # print(x.tm_year)
# print(time.strftime("%Y-%m-%d %H:%M:%S",x))    # convert tuple to str(自定义)
# print(time.strptime('2018-10-28 21:09:51',"%Y-%m-%d %H:%M:%S")) #convert str to tuple
# print(time.asctime())           #convert tuple to str(固定格式)
# print(time.ctime())             #convert second to str(固定格式)
import datetime
print(datetime.datetime.now())  #现在的时间  格式化输出年月日  时分秒
# print(datetime.datetime.now()+datetime.timedelta(3))    #三天后的时间
# print(datetime.datetime.now()+datetime.timedelta(-3))     #三天前的时间
print(datetime.datetime.now()+datetime.timedelta(hours = 3))    #三个小时以后的时间
print(datetime.datetime.now()+datetime.timedelta(hours = -3))   #三个小时以前的时间

  

原文地址:https://www.cnblogs.com/Json28/p/11020561.html