检查字符串是否仅包含日期,没有时间戳
我试图检测字符串是否包含没有时间戳的日期。日期和时间戳可以采用不同的格式。
我尝试用Python-dateutil解析字符串,但它返回包含时间戳的DateTime实例。
import dateutil.parser
print(dateutil.parser.parse("2020-01-01"))
print(dateutil.parser.parse("2020-01-01 01:24:37 UTC"))
返回
2020-01-01 00:00:00
2020-01-01 01:24:37+00:00
I am trying to detect if a string contains a date without a timestamp. The date and timestamp can be in different formats.
I tried parsing the strings with python-dateutil, but it returns a datetime instance which contains a timestamp.
import dateutil.parser
print(dateutil.parser.parse("2020-01-01"))
print(dateutil.parser.parse("2020-01-01 01:24:37 UTC"))
returns
2020-01-01 00:00:00
2020-01-01 01:24:37+00:00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将REGEX用于此目的,因为您的输入是一个
输出的字符串:
REGEX说明:
You could use regex for that purpose, since your input is a string
Which outputs:
Regex explanation: