time模块

匿名 (未验证) 提交于 2019-12-02 23:42:01
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))   #三个小时以前的时间 

  

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!