如何将字符串格式化日期转换为纪元格式。就像给出日期是这种格式2018, June 12th
如何将它转换为python中的纪元?
答案 0 :(得分:0)
您可以将python datetime用于所有与日期时间相关的转换。
fstring = "%Y, %B %d"
end = {"th" : fstring + "th", "rd": fstring + "rd"}
days = ["2018, June 12th", "2018, June 3rd"]
for day in days:
fstr = end["rd"] if day.endswith("rd") else end["th"]
print(datetime.datetime.strptime(day, fstr).timestamp())
1528741800.0
1527964200.0
更多信息here