码迷,mamicode.com
首页 > 编程语言 > 详细

python时间

时间:2018-01-12 13:31:24      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:时间   blog   .com   注意   com   格式   str   python   5.5   

涉及对象

1.datetime


 

import datetime
x=datetime.datetime.now()    #2018-01-10 16:45:25.474000 
x=datetime.datetime.now().date()     #2018-01-10
x=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")    #‘2018-01-10 10:10:12‘   只有这个输出的是字符串格式,其他的都是日期格式
x=datetime.datetime.today()    #2018-01-10 11:18:52.079000

注意:
>>> datetime.datetime.now()
datetime.datetime(2018, 1, 12, 11, 24, 54, 7000)
>>> print datetime.datetime.now()
2018-01-12 11:25:06.615000
>>> print datetime.datetime.combine(datetime.date.today(),datetime.time.min)
2018-01-12 00:00:00
>>> print datetime.datetime.combine(datetime.date.today(),datetime.time.max)
2018-01-12 23:59:59.999999
>>> print (datetime.datetime(2018,1,1,1,1,1)-datetime.datetime.now()).total_seconds()
-988227.107

x=datetime.date.today()      #2018-01-10
x=datetime.date.today() + datetime.timedelta(days=1)     #2018-01-11

 

2.time


 

import time
time.time() #1421075455.568243
time.loacaltime() #time.struct_time(tm_year=2018, tm_mon=1, tm_mday=10, tm_hour=16, tm_min=55, tm_sec=26, tm_wday=2, tm_yday=10, tm_isdst=0)

3.calendar


 

python时间

标签:时间   blog   .com   注意   com   格式   str   python   5.5   

原文地址:https://www.cnblogs.com/zz27zz/p/8267325.html

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