国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python time datetime模塊使用方法記錄

2019-11-06 07:34:45
字體:
來源:轉載
供稿:網友
import timeimport datetime#time datetime使用方法備份PRint(time.clock())# 4.665275792443746e-07 返回處理器時間print(time.process_time())# 0.0780005print(time.time())# 1488616321.8451998 返回當前時間戳 <class 'float'>print(time.ctime())# Sat Mar 4 16:34:51 2017 格式化返回系統時間 <class 'str'>print(time.ctime(887665))# Sun Jan 11 14:34:25 1970print(time.ctime(time.time() - 60*60*24 ))# Fri Mar 3 16:39:17 2017 輸出前一天print(time.gmtime())# time.struct_time(tm_year=2017, tm_mon=3, tm_mday=4, tm_hour=8, tm_min=41, tm_sec=32, tm_wday=5, tm_yday=63, tm_isdst=0)# <class 'time.struct_time'> 格林尼治時間print(time.localtime())# time.struct_time(tm_year=2017, tm_mon=3, tm_mday=4, tm_hour=16, tm_min=43, tm_sec=43, tm_wday=5, tm_yday=63, tm_isdst=0)# <class 'time.struct_time'> 當地時間# !!此時時間格式為struct_timeprint(time.mktime(time.localtime()))# 1488617178.0# 將struct_time時間轉化為float格式的時間print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time() - 60*60*24)))# 2017-03-03 16:59:15# 將struct_time轉化為字符串類型的時間# 首先:time.time() 為float格式 time.localtime() 的輸入格式即為float,輸出格式為struct_time# time.strftime 又將struct_time 轉化為字符串輸出格式print(time.strptime('2017-03-03 16:59:15',"%Y-%m-%d %H:%M:%S"))# time.struct_time(tm_year=2017, tm_mon=3, tm_mday=3, tm_hour=16, tm_min=59, tm_sec=15, tm_wday=4, tm_yday=62, tm_isdst=-1)# 與strftime相反,輸入為字符串格式,按照格式對應的字段轉化為struct_time格式# '2017-03-03 16:59:15'與"%Y-%m-%d %H:%M:%S"是一一對應的。# datetimeprint(datetime.date.today(),type(datetime.date.today()))# 2017-03-04 <class 'datetime.date'># 當前日期print(datetime.date.fromtimestamp(time.time() - 60*60*24))# 2017-03-03# 將float格式的時間戳轉化為<class 'datetime.date'>格式current_time = datetime.datetime.now()print(current_time)# 2017-03-04 17:20:41.851214 當前時間print(current_time.timetuple())# time.struct_time(tm_year=2017, tm_mon=3, tm_mday=4, tm_hour=17, tm_min=21, tm_sec=42, tm_wday=5, tm_yday=63, tm_isdst=-1)# 將<class 'datetime.date'> 轉化為 <class 'time.struct_time'>print(current_time.replace(2012))# 2012-03-04 17:29:53.446764# 替換時間并輸出newtime = datetime.datetime.now() - datetime.timedelta(days=3)print(datetime.datetime.now(),'/t',newtime)# 2017-03-04 17:32:47.736732 2017-03-01 17:32:47.736732# days=3 為3天時間 -號則表示3天前
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巫山县| 浮山县| 中超| 泽普县| 安图县| 金秀| 齐齐哈尔市| 六安市| 齐河县| 合川市| 义乌市| 苍梧县| 惠水县| 福贡县| 巧家县| 林周县| 惠州市| 沅陵县| 长寿区| 锡林郭勒盟| 永善县| 延寿县| 梅州市| 宜君县| 元氏县| 平远县| 剑河县| 涞水县| 大洼县| 珠海市| 定陶县| 林州市| 邻水| 宜兰市| 文水县| 伊宁市| 象州县| 安西县| 砀山县| 盐城市| 屏山县|