Back to skills
SKILL.md
Python日期字符串标准化转换函数
ASecurity编写Python函数,将包含或不包含时间部分的日期字符串(如'2023/6/26 15:00'或'2023/6/26')统一转换为datetime.date对象。
- 611 stars
- 0 votes
- 0 copies
- 0 views
- Added November 11, 2026
Security analysis
100/100npx -y skills add ECNU-ICALK/AutoSkill --skill 'python日期字符串标准化转换函数' --agent claude-codeAre you the author of Python日期字符串标准化转换函数?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ecnu-icalk-python-8da5547e)---
id: "2ac2773d-067e-488b-b43f-c1162b5c684f"
name: "Python日期字符串标准化转换函数"
description: "编写Python函数,将包含或不包含时间部分的日期字符串(如'2023/6/26 15:00'或'2023/6/26')统一转换为datetime.date对象。"
version: "0.1.0"
tags:
- "python"
- "datetime"
- "parsing"
- "function"
- "date-conversion"
triggers:
- "编写一函数处理日期和时间"
- "日期字符串转date对象"
- "如何统一转换不同格式的日期"
- "python日期解析函数"
---
# Python日期字符串标准化转换函数
编写Python函数,将包含或不包含时间部分的日期字符串(如'2023/6/26 15:00'或'2023/6/26')统一转换为datetime.date对象。
## Prompt
# Role & Objective
编写一个Python函数,用于将日期字符串转换为datetime.date对象。
# Operational Rules & Constraints
1. 输入字符串可能包含时间部分(例如 "2023/6/26 15:00"),也可能不包含(例如 "2023/6/26")。
2. 函数必须能够处理这两种输入情况。
3. 输出结果必须是datetime.date对象。
4. 日期格式通常为 "YYYY/M/D" 或 "YYYY/M/D H:M"。
# Interaction Workflow
1. 接收日期字符串作为输入。
2. 尝试按照带时间的格式(如 "%Y/%m/%d %H:%M")解析字符串。
3. 如果解析失败,则尝试按照仅日期的格式(如 "%Y/%m/%d")解析字符串。
4. 返回解析后的datetime.date对象。
## Triggers
- 编写一函数处理日期和时间
- 日期字符串转date对象
- 如何统一转换不同格式的日期
- python日期解析函数
Attribution
Related skills
View all in education →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.