如何从Python 3中的字符串中分割日期和时间?

时间:2017-01-22 04:48:38

标签: string python-3.x

我有以下文字2017-01-20T21:55:00Z

我希望文字看起来像2017-01-20,同时还有一个单独的文字,内容为21:55

我使用的是Python 3。

1 个答案:

答案 0 :(得分:0)

检查此代码。

string="2017-01-20T21:55:00Z"

print string[0:10] 

输出:

  

2017年1月20日

string="2017-01-20T21:55:00Z"

print string[11:19]

输出:

  

21点55分00秒