python 時間

#設a爲字符串數組

import time字符串

a = "2011-09-28 10:00:00"import

 

#中間過程,通常都須要將字符串轉化爲時間數組im

time.strptime(a,'%Y-%m-%d %H:%M:%S')時間戳

>>time.struct_time(tm_year=2011, tm_mon=9, tm_mday=27, tm_hour=10, tm_min=50, tm_sec=0, tm_wday=1, tm_yday=270, tm_isdst=-1)時間

 

#將"2011-09-28 10:00:00"轉化爲時間戳字符

time.mktime(time.strptime(a,'%Y-%m-%d %H:%M:%S'))time

>>1317091800.0日期

 

#將時間戳轉化爲localtimestruct

x = time.localtime(1317091800.0)

time.strftime('%Y-%m-%d %H:%M:%S',x)

 

#獲取當前日期

time.strftime("%Y-%m-%d")

>>>'2015-03-13'

 

#獲取當前時間

 

time.strftime("%Y-%m-%d %H:%M:%S")

>>>'2015-03-13 20:26:22'

相關文章
相關標籤/搜索