以import datetime开头,以10种不同日期格式输出2003年8月27日12点0分0秒
时间: 2024-04-08 14:34:50 浏览: 10
以下是使用Python的datetime模块以不同日期格式输出2003年8月27日12点0分0秒的示例代码:
```python
import datetime
# 创建一个表示2003年8月27日12点0分0秒的datetime对象
date = datetime.datetime(2003, 8, 27, 12, 0, 0)
# 输出不同日期格式
print(date.strftime("%Y-%m-%d %H:%M:%S")) # 2003-08-27 12:00:00
print(date.strftime("%m/%d/%Y %I:%M:%S %p")) # 08/27/2003 12:00:00 PM
print(date.strftime("%B %d, %Y %H:%M:%S")) # August 27, 2003 12:00:00
print(date.strftime("%A, %d %B %Y %I:%M:%S %p")) # Wednesday, 27 August 2003 12:00:00 PM
print(date.strftime("%Y-%m-%d")) # 2003-08-27
print(date.strftime("%m/%d/%y")) # 08/27/03
print(date.strftime("%B %d, %Y")) # August 27, 2003
print(date.strftime("%A, %d %B %Y")) # Wednesday, 27 August 2003
print(date.strftime("%H:%M:%S")) # 12:00:00
print(date.strftime("%I:%M:%S %p")) # 12:00:00 PM
```
在上述代码中,我们使用`strftime()`方法将datetime对象按照指定的格式进行输出。每个格式化字符串都代表不同的日期格式,可以根据需要选择适合的格式。