python - dateutil.parser handles incomplete time strings
过去多啦不再A梦
过去多啦不再A梦 2017-06-12 09:27:04
0
2
797

parse function is powerful and convenient, and it is easy to handle time analysis in various string forms. However, when encountering an incomplete time format, such as '8-9 12:00', it can also be automatically parsed into 2017-8- 9 12:00, the default current year is used to complete the missing content.

The issue is

Is there a way to directly obtain the parsed string without automatically completing the missing parts?

Sorry, the question is not detailed enough, please add more.
For example "Juanary 1, 12:00"
Parse to get <datetime> 2017-1-1 12:00:00
All I need is <str> 1-1 12:00

In other words, I hope to block the automatic completion function and only need the parsed string of the actual content. Is there any good way to achieve this?

I checked the official documentation and found that there is no corresponding function. There is just a time template that is set to be replaced by default.

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
阿神

Can’t we use datetime’s strftime to format it?

print parse('2017-1-1 12:00:00').strftime('%m-%d %H:%M')
学习ing

It is indeed possible, but I have no way to determine whether the obtained data has been completed and which parts have been completed.
That’s the trouble.
Is there any way to deal with it?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!