From the course: Learning Python

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Formatting time output

Formatting time output - Python Tutorial

From the course: Learning Python

Formatting time output

- [Instructor] Now that we've seen how to retrieve basic date and time information in Python, let's take a look at how to format that information using a set of predefined string formatting codes. So in my editor, I'm going to open up the formatting start example. Now, in this example, I have already set up the import statement to import the date time class, so you don't need to do that. And Python provides a standard set of string formatting codes that you can use in a variety of scenarios. Now, if you've ever done any programming in C or C++, and used the standard C library, some of these codes might look familiar to you. If not, they're pretty easy to understand once you've seen them in action. So let's start with a familiar piece of code to get the current date and time. So, I'm going to create a variable called now, and I'm going to call it datetime.now. So now I've got the current date and time. Let's have a look…

Contents