I like to parse datetime strings with dateutil.parser.parse
module. It's simple. However I noticed in my code that I have to check if the object is indeed in 8601 (and aware).
My structure is:
if parse(datetime).tzinfo==None:
#do something
else:
#make it aware
#do something
and I want to achieve something like:
if <IS-8601>:
if parse(datetime).tzinfo==None:
#do something
else:
#make it aware
#do something
else:
pass
If I have a 8601 like e.g. 2014-02-28T22:30:00+0200
parse utility does its job.
If I have however a 2014-03-20
string parse will add time on the object. That's not wrong, just unwanted: 2014-03-20 00:00:00
So how can I check if an object is in 8601? And if in 8601, is it aware? I don't mind change to another datetime library.
re.compile(r'^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$')
– MenorrhagiaZ
instead of offset and can also have milliseconds. – Urmia