是否有任何簡短的方法來將此ISO 8601兼容UTC時間轉換爲SQL DATETIME格式?如何將日期時間字符串轉換爲sql格式?
>>> str = "2016-03-28T20:23:46+0800"
>>> temp = str.split('T')
>>> temp[1] = temp[1].rstrip('+')
>>> temp[1]
'20:23:46+0800'
>>> temp[1] = temp[1].split('+')[0]
>>> result = " ".join(temp)
>>> result
'2016-03-28 20:23:46'
謝謝!
我希望您不打算將此結果格式化或連接到查詢字符串。 –
我打算把它寫成一個元組的屬性,是的,什麼? – paus
http://stackoverflow.com/questions/12281975/convert-timestamps-with-offset-to-datetime-obj-using-strptime – lesingerouge