a = '0|2|alarm_xue|2019-01-25'
print 'a[-10:] = ', a[-10:]
time_str = a[-10:] +' 00:00:00'
print 'time_str = ', time_str
import time
hehe = time.mktime(time.strptime(time_str, '%Y-%m-%d %H:%M:%S'))
print 'int(hehe*1000) = ', int(hehe*1000)
########################################
# 执行结果
a[-10:] = 2019-01-25
time_str = 2019-01-25 00:00:00
int(hehe*1000) = 1548345600000
本文展示了一段Python代码,该代码演示了如何从字符串中提取特定部分,并将其转换为时间戳。首先,代码初始化了一个包含日期信息的字符串,然后通过切片操作获取最后10个字符,即日期部分。接下来,将此日期字符串与默认时间为00:00:00拼接,并使用Python的时间模块将其转换为时间戳。最后,输出转换后的时间戳。
543

被折叠的 条评论
为什么被折叠?



