你可以使用 Python 中的 datetime 模块来实现日期的转换。下面是一个示例代码:

from datetime import datetime

date_str = '2022-04-26'
date_obj = datetime.strptime(date_str, '%Y-%m-%d')
formatted_date = date_obj.strftime('%Y年%m月%d日')

print(formatted_date)

输出结果为:

2022年04月26日

在代码中,首先使用 strptime 方法将字符串类型的日期转换为 datetime 对象,然后使用 strftime 方法将 datetime 对象转换为指定格式的字符串。在 strftime 方法中,%Y 代表四位数的年份,%m 代表两位数的月份,%d 代表两位数的日期。


原文地址: https://www.cveoy.top/t/topic/pZxl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录