CPython - 使用计算机上的日期显示日期

CPython - Making the date show up using the date on your computer

我真的是编程新手,我才刚刚开始使用 Python,如果有人可以编辑我提供的代码以使其按我希望的方式运行,请这样做。

我想知道我是否可以让日期显示在我的 python 程序中,但在不同地区让它有所不同,所以如果有人在英国打开该程序,日期会首先显示,如果在美国它会先显示月份或年份等等。

这是我目前所拥有的。

import datetime
currentDate = datetime.date.today()
print(currentDate.strftime('Todays date is: %d %B %Y'))

我目前已将其设置为先显示日期,然后显示月份,然后显示年份。

是否可以根据您所在的国家/地区以不同的顺序使用它?

这对你有用吗?

>>> import datetime
>>> today = datetime.date.today()
>>> print(today.strftime('%x'))
09/10/15

具体来说,您可能应该查看 %c%x%X 格式代码。有关如何使用 strftime 方法的更多信息,请参阅 8.1.8. strftime() and strptime() Behavior