Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Parse Strings into Datetime Objects | Python Basics: Date and Time Mastery
Python Basics: Date and Time Mastery
course content

Contenido del Curso

Python Basics: Date and Time Mastery

Parse Strings into Datetime Objects

In the last chapter, we have converted a datetime object into a string. Now we will do the opposite, from a String we will create a datetime object via the strptime() function. The strptime() function will try to parse the string according to the specified format, and if successful, it will return a datetime object representing the date and time. If the string cannot be parsed according to the specified format, strptime() will raise a ValueError exception.

You can find a list of all the available format codes in the documentation for the datetime module. These format codes can be used with both strftime() and strptime() to specify the format of dates and times.

Tarea

  1. Create a datetime object with the format "%Y-%m-%d %H:%M:%S" and print it;
  2. Create a datetime object with the format "%d %B, %Y" and print it.

Tarea

  1. Create a datetime object with the format "%Y-%m-%d %H:%M:%S" and print it;
  2. Create a datetime object with the format "%d %B, %Y" and print it.

Mark tasks as Completed
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

In the last chapter, we have converted a datetime object into a string. Now we will do the opposite, from a String we will create a datetime object via the strptime() function. The strptime() function will try to parse the string according to the specified format, and if successful, it will return a datetime object representing the date and time. If the string cannot be parsed according to the specified format, strptime() will raise a ValueError exception.

You can find a list of all the available format codes in the documentation for the datetime module. These format codes can be used with both strftime() and strptime() to specify the format of dates and times.

Tarea

  1. Create a datetime object with the format "%Y-%m-%d %H:%M:%S" and print it;
  2. Create a datetime object with the format "%d %B, %Y" and print it.

Mark tasks as Completed
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 4
AVAILABLE TO ULTIMATE ONLY
We're sorry to hear that something went wrong. What happened?
some-alt