In this tutorial, we will learn about how to convert timestamp to datetime objects as well as datetime to timestamp.You will get them with the help of examples.
It's pretty common to store date and time as a timestamp in a database.
A Unix timestamp is the number of seconds between a particular date and January 1, 1970 at UTC.
Output:
We can see in the above code we used datetime module to convert timestamp in datetime.We used datetime.fromtimestamp() function which helped us to decode the timestam.After decoding we assigned it to date_object an alo print them by using print statement.
We can check that the output of the program is same as the input we provided as timestamp in the first program.
We can see in above code how to convert datetime to timestamp. We have to provide a date in the format datetime() and this will help us to know the timestamp.
You can also find the timestamp of the current time without using datetime method
. Example:
You can see in the above code that we used datetime.now() method to access the current time and the other process is same as previous one.