Python · Dates & Times

How do you build a datetime from a Unix timestamp, and from an existing datetime back to a timestamp?

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Dates & Times

In the datetime module, which type holds a calendar day only (no clock), which holds a wall-clock time only, and which combines both?
You subtract two datetime objects to get a duration. What type comes back, and what do you call to turn it into a plain number of seconds?
What does this print? ``` from datetime import timedelta d = timedelta(days=32, seconds=29700) print(d.seconds) ```
strftime vs strptime: which one turns a datetime into a formatted string, and which parses a string into a datetime?
You want to parse '19.09.2007 14:30:00' into a datetime. What's wrong with this? ``` datetime.strftime(s, '%d.%m.%Y %H:%M:%S') ```
In strftime/strptime format codes, what's the difference between %Y, %m, %M, and %d?

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play