Question:
I have code that returns a CkSFtpFile object from the SFTP library in Python, but I need to convert the file modified datetime to a standard Python datetime.
Assuming I have CkSFtpFile object which returns a CkDateTime object, how do I convert this to a Python datetime?
The solution is to find an intermediate format that can be used to construct a Python datetime. One possibility is to use a UTC Unix time.
You should be able to do it like this:
(Assuming that "ckdt" is a CkDateTime object.) datetime.datetime.utcfromtimestamp(ckdt.getAsUnixTimeStr(False)).strftime('%Y-%m-%dT%H:%M:%SZ')
Or like this:
datetime.datetime.utcfromtimestamp(float(ckdt.getAsUnixTimeStr(False))).strftime('%Y-%m-%dT%H:%M:%SZ')