//parses some string into that format.
datetime1 = datetime.strptime(somestring, "%Y-%m-%dT%H:%M:%S")
//gets the seconds from the above date.
timestamp1 = time.mktime(datetime1.timetuple())
//adds milliseconds to the above seconds.
timeInMillis = int(timestamp1) * 1000
我如何(在该代码中的任何点)将日期转换为UTC格式?我一直在通过这个看起来像是一个世纪的API而无法找到任何我可以工作的东西.有人可以帮忙吗?目前它正在把它变成东部时间,我相信(但我是GMT但想要UTC).
编辑:我给了最接近我最终发现的人的答案.
datetime1 = datetime.strptime(somestring, someformat)
timeInSeconds = calendar.timegm(datetime1.utctimetuple())
timeInMillis = timeInSeconds * 1000