login about faq

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?

asked May 17 at 08:33

chilkat's gravatar image

chilkat ♦♦
12.8k317367481


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.

See http://stackoverflow.com/questions/3682748/converting-unix-timestamp-string-to-readable-date-in-python

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')

link

answered May 17 at 08:38

chilkat's gravatar image

chilkat ♦♦
12.8k317367481

Or like this:

datetime.datetime.utcfromtimestamp(float(ckdt.getAsUnixTimeStr(False))).strftime('%Y-%m-%dT%H:%M:%SZ')

link

answered May 23 at 14:40

chilkat's gravatar image

chilkat ♦♦
12.8k317367481

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×21
×5

Asked: May 17 at 08:33

Seen: 321 times

Last updated: May 23 at 14:40

powered by OSQA