I want to validate dates in some RFC defined formats. The problem is that the timezone could differ eg
24 Dec 1991 23:59:23 UTC
24 Dec 1991 23:59:23 EST
24 Dec 1991 23:59:23 CST
And I expanded upon this code which works nicely How to validate a specific Date and Time format using Python
def validate_date(d):
try:
datetime.strptime(d, '%d %b %Y %H:%M:%S %Z')
return True
except ValueError:
return False
As long as the timezone is UTC (my local).
I could change my local timezone I suppose Setting timezone in Python
But then I would need to extract the last part of the string and test it but it feels messy. Then I rather go with a complete regex solution.
I'm looking into http://labix.org/python-dateutil, not sure how to use it for this problem though.