Python 3.x 在python 3中将字符串更改为日期格式

Python 3.x 在python 3中将字符串更改为日期格式,python-3.x,Python 3.x,月份:11 日期:1 年份:2016年 ('11','11','2016')您不需要datetime模块的功能,只需执行以下操作: x = (input("month: "), input("day: "), input("Year: ")) 如果你想让它看起来漂亮,像蟒蛇: >>> x = input("month: ") + '/' + input("day: ") + '/' + input("year: ") month: 11 day: 01 year: 2016

月份:11 日期:1 年份:2016年
('11','11','2016')您不需要datetime模块的功能,只需执行以下操作:

x = (input("month: "), input("day: "), input("Year: "))
如果你想让它看起来漂亮,像蟒蛇:

>>> x = input("month: ") + '/' + input("day: ") + '/' + input("year: ")
month: 11
day: 01
year: 2016
>>> x
'11/01/2016'

Datetime在这里帮不了你,因为它的格式主要适用于时间数学。

主要有两种方法。您可以使用
“/”。join(x)
将元组连接到一个字符串,也可以将月/日/年输入。
>>> x = "%s/%s/%s" % (input("month: "), input("day: "), input("year: "))
month: 11
day: 01
year: 2016
>>> x
'11/01/2016'