It depends on what python interpreter you use:
Jython:
If you use Jython, then the Job variable of type DateTime are, as mentioned, instances of MatillionDate
and not datetime
. You can convert it back to datetime.datetime
, by converting it to a Java's Instant
, getting the ISO 8601 representation and parsing that:
from dateutil.parser import parse
from dateutil.tz import tzutc
as_iso_string = str(latest_updated.toInstant()) # 2000-01-01T00:00:00Z
asdt = parse(as_iso_string) # datetime.datetime(2000, 1, 1, 0, 0, tzinfo=tzlocal())) tzinfo should be tzutc() not tzlocal()
asdt = parse(as_iso_string).replace(tzinfo=None) # naive datetime
asdt = parse(as_iso_string).replace(tzinfo=tzutc()) # datetime.datetime(2000, 1, 1, 0, 0, tzinfo=tzutc())
Make sure that you get the timezone right, if your Job variable was meant to be in UTC you will need to do .replace(tzinfo=tzutc())
as for some reason dateutil.parser.parse()
in Jython is not parsing the Z
as timezone UTC (it does in regular python 2.7.12)
Python 2 / Python 3:
The variable would have the right type already datetime.datetime
. No timezone
print(repr(latest_updated)) # datetime.datetime(2000, 1, 1, 0, 0)