在python中将mysql时间戳转换为纪元时间,有没有简单的方法来做到这一点?
发布于 2018-06-22 14:39:01
将MySQL时间转换为时代:
>>> import time
>>> import calendar
>>> mysql_time = "2010-01-02 03:04:05"
>>> mysql_time_struct = time.strptime(mysql_time, '%Y-%m-%d %H:%M:%S')
>>> print mysql_time_struct
(2010, 1, 2, 3, 4, 5, 5, 2, -1)
>>> mysql_time_epoch = calendar.timegm(mysql_time_struct)
>>> print mysql_time_epoch
1262401445
将时代转换为MySQL可以使用的东西:
>>> import time
>>> time_epoch = time.time()
>>> print time_epoch
1268121070.7
>>> time_struct = time.gmtime(time_epoch)
>>> print time_struct
(2010, 3, 9, 7, 51, 10, 1, 68, 0)
>>> time_formatted = time.strftime('%Y-%m-%d %H:%M:%S', time_struct)
>>> print time_formatted
2010-03-09 07:51:10
发布于 2018-06-22 15:39:49
为什么不让MySQL努力工作?
从表名中选择unix_timestamp(fieldname);
https://stackoverflow.com/questions/-100000313
复制相似问题