日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:time.localtime在python中的使用

本文教程操作環(huán)境:windows7系統(tǒng)、python 3.9.1,DELL G3電腦。

1、說明

將一個時間戳轉(zhuǎn)換為當前時區(qū)的struct_time。secs參數(shù)未提供,則以當前時間為準。

2、語法

time.localtime([ sec ])

3、參數(shù)

sec -- 轉(zhuǎn)換為time.struct_time類型的對象的秒數(shù)。

4、返回值

該函數(shù)沒有任何返回值。

5、實例

import time
 
import re
 
print time.time()
 
print time.localtime()
 
a = 'tm_year=2016, tm_mon=5, tm_mday=28, tm_hour=6, tm_min=51, tm_sec=14, tm_wday=5, tm_yday=149, tm_isdst=0'
 
b = re.findall('\d+', a)
 
print b
 
c = []
 
for tup in b:
 
t = int(tup)
 
c.append(t)
 
c = tuple(c)
 
print type(c)
 
print c
 
# c = (2016, 5, 28, 6, 51, 14, 5, 149, 0)
 
print time.mktime(c)
 
print time.mktime(time.localtime(1464389474.0)) # 元組轉(zhuǎn)化為時間戳,struct_time --->時間戳
 
print time.localtime(1464389474.0)
 
print time.gmtime(1464389474.0) # 時間戳轉(zhuǎn)化為元組, 時間戳--->struct_time
 
print time.strftime('%Y-%m-%d %H:%M:%S:%a:%b:%c:%j %p %U %w %W %x', time.localtime(1464389474.0))
 
print time.strftime('%Y-%m-%d %H:%M:%S') # struct_time --->格式化字符串
 
print time.strptime('2016-05-28 06:51:14', '%Y-%m-%d %H:%M:%S') #格式化字符串 --->struct time
 
#元組和字符串無法直接相互轉(zhuǎn)化
 
#datetime

時間的計算是python中比較重要的模塊,跟我們的實際生活結合也比較緊密。本篇要帶來的是一種轉(zhuǎn)換成本地時間的方法,名稱對應為time.localtime,相信大家現(xiàn)在已經(jīng)有所了解了。

以上就是time.localtime在python中的使用,對于這種特定的時間函數(shù)來說,其轉(zhuǎn)換的方法也是固定的。大家學會后可以就代碼的部分進行練習。


當前題目:創(chuàng)新互聯(lián)Python教程:time.localtime在python中的使用
轉(zhuǎn)載注明:http://www.dlmjj.cn/article/cdddjhp.html