Matching dates with regular expressions in Python?

后端 未结 6 1801
-上瘾入骨i
-上瘾入骨i 2020-12-31 17:56

I know that there are similar questions to mine that have been answered, but after reading through them I still don\'t have the solution I\'m looking for.

Using Pyth

6条回答
  •  梦谈多话
    2020-12-31 18:23

    Python has a date parser as part of the time module:

    import time
    time.strptime("December 31, 2012", "%B %d, %Y")
    

    The above is all you need if the date format is always the same.

    So, in real production code, I would write a regular expression that parses the date, and then use the results from the regular expression to build a date string that is always the same format.

    Now that you said, in the comments, that this is homework, I'll post another answer with tips on regular expressions.

提交回复
热议问题