开发者

String to DATETIME in MySQL

I would like to convert string开发者_如何学Gos to datetime objects to be used in the insert statement for MySQL. The strings are received in the following format :

2010-12-21T22:57:04.000Z

The data type of the MySQL column is DATETIME.


You can use the strptime function.

For instance, that would give:

myDatetime = datetime.strptime(myString.split(".")[0], "%Y-%m-%dT%H:%M:%S")

[EDIT] Well, I've seen this has been treated in another thread with a better answer than mine: How to parse an ISO 8601-formatted date?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜