05-06-2016 00:00:00 translate this into format in python

To translate the date and time "05-06-2016 00:00:00" into a specific format in Python, you can use the strptime() and strftime() functions from the datetime module.

Here's an example code that demonstrates the conversion:

main.py
from datetime import datetime

# Input datetime string
datetime_str = "05-06-2016 00:00:00"

# Convert string to datetime object using strptime()
datetime_obj = datetime.strptime(datetime_str, "%d-%m-%Y %H:%M:%S")

# Format the datetime object using strftime()
formatted_datetime = datetime_obj.strftime("%Y-%m-%d %H:%M:%S")

print(formatted_datetime)
352 chars
13 lines

In the code above, the strptime() function is used to convert the input datetime string into a datetime object with the specified format ("%d-%m-%Y %H:%M:%S"). Then, the strftime() function is used to format the datetime object into the desired format ("%Y-%m-%d %H:%M:%S").

The output of the code will be: "2016-06-05 00:00:00", which is the input datetime string formatted as "YYYY-MM-DD HH:MM:SS".

related categories

gistlibby LogSnag