码迷,mamicode.com
首页 > 其他好文 > 详细

time模块

时间:2019-06-14 01:12:02      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:pre   timezone   自定义   print   时区   time()   datetime   cti   年月日   

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))   #三个小时以前的时间

  

time模块

标签:pre   timezone   自定义   print   时区   time()   datetime   cti   年月日   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!