Python转换GMT时间为时间戳,并计算时间差

Apache日志中的时间是GMT格式,如下:


[Fri Oct 20 06:26:24 2017] [error] Server certificate is expired: 'Server-Cert'


用Python转换时间戳,和系统时间比较时间差的代码如下:


import time
time.ctime(time.time())
#'Tue Oct 31 15:38:18 2017'


time.mktime(time.strptime(time.ctime(time.time()),"%a %b %d %H:%M:%S %Y"))


time.mktime(time.strptime("Tue Oct 31 15:38:18 2017","%a %b %d %H:%M:%S %Y"))

#计算时间差
int(time.mktime(time.strptime(time.ctime(time.time()),"%a %b %d %H:%M:%S %Y"))-time.mktime(time.strptime("Tue Oct 31 15:38:18 2017","%a %b %d %H:%M:%S %Y")))


你可能感兴趣的:(Linux运维)