斜杠换成年月日

文章介绍了一段Python代码,用于将日期从2022/9/21这样的格式转换为2022年9月21日的格式,适用于毕业设计中修改时间填写的要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近毕业设计,填时间,之前填的是斜杠,现在要换年月日,于是就写了一个python代码


i = [
"2022/9/21","2022/10/30"
,"2022/11/1","2022/12/25"
,"2022/12/26","2023/1/4"
,"2023/1/5","2023/1/15"
,"2023/1/16","2023/3/15"
,"2023/3/16","2023/3/25"
,"2023/3/26","2023/4/20"
,"2023/4/21","2023/5/5"
,"2023/5/6","2023/5/18"
]

i4 = [];
for i1 in i:
	count = 0;
	str = "";
	for i2 in i1:
		if (i2 == "/") & (count == 0):
			str = str + "年";
			count = count + 1;
			continue;
		elif (i2 == "/") & (count == 1):
			str = str + "月";
			count = count + 1;
			continue;
		else:
			str = str + i2;
			continue
	print(str+"日")

f非常容易

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值