Timezone Aware Datetime To String?
I am retrieving a timezone aware DateTime object from my postgres db. Now I want to convert this datetime object into it's string representation. Normally I would do something like
Solution 1:
Here is a simple example of how to convert a datetime
object to a string
:
import datetime
import pytz
x = datetime.datetime(2016, 1, 15, 9, 59, 45, 165904, tzinfo=pytz.UTC)
print(datetime.datetime.strftime(x, "%d/%m/%Y"))
Output
15/01/2016
Options for the format string to pass into the strftime()
function are in the Python documentation.
Post a Comment for "Timezone Aware Datetime To String?"