转换时间戳

问题描述 投票:0回答:1

[嘿,我目前的时间戳记为:“ 10-07-2019T19-45-12”,但是我希望它像1562770279430一样在unixtime中使用,以便在计算中使用时间戳记。可以使用python中的哪些功能/模块轻松做到这一点?

python-3.x timestamp iso
1个回答
0
投票

您可以使用datetime.strptime函数将字符串转换回日期时间对象。

Example

import datetime

date_time_str = '2018-06-29 08-15-27'
date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H-%M-%S')

print('Date:', date_time_obj.date())
print('Time:', date_time_obj.time())
print('Date-time:', date_time_obj)
© www.soinside.com 2019 - 2024. All rights reserved.