I have this string '2015-04-08T07:52:00Z'
and I wanna to convert it to '08/04/2015'
, how can I do this?
The constructor of the Date class receives a long value as an argument. Since the constructor of the Date class requires a long value, we need to convert the Timestamp object into a long value using the getTime() method of the TimeStamp class(present in SQL package).
For this, we will use the strptime() method and Pandas module. This method is used to create a DateTime object from a string. Then we will extract the date from the DateTime object using the date() function and dt. date from Pandas in Python.
We can convert a string to datetime using strptime() function. This function is available in datetime and time modules to parse a string to datetime and time objects respectively.
You can use the datetime.datetime.strptime()
function to create a datetime object, then datetime.datetime.strftime()
to return your correctly formatted date like so:
from datetime import datetime
dt = datetime.strptime('2015-04-08T07:52:00Z', '%Y-%m-%dT%H:%M:%SZ')
print dt.strftime('%d/%m/%Y')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With