 Hi everyone, in this tutorial, we're going to talk about date and time in Python language and we're going to cover the topic how to get and format current date and time in Python language. When we're working in Python or other programming language, sometimes we need to have a string that contains current date and time. So how to get and format current date and time? In this video, we're going to answer to this question. In order to get current date and time in certain format, first, we need to import time module. I'm going to open my Python IDLE and I'm going to import time module and then I'm going to press enter. Then second thing what we need to do is that we're going to use string format time function and this function is from time module. So we've already imported time module, so we can use string format time function in our future examples. But before we start working with this function, I want to say a few words about this string format time function returns a string with date and time in a format that we provide to this function. So this function is going to return to us a string that contains date and time that we want to be presented in a format that we want. This function has two arguments. First argument is for string format and second argument is time. First I'm going to say a few words about the second argument time. When we're working with this function, we can provide time on two different ways. First is GMT time, which tends for green which mean time or GMT. But now this GMT time is superseded by coordinated universal time or UTC. And second time that we can use inside our function is local time. In this video, I'm gonna use just local time function to provide the current time. Let me give you an example. We're going to use this function string format time. We're gonna call it from the time module. And inside it, we need to put two arguments. But I'm going to use a first argument as an empty string, because in this example, I'm gonna show you how you can work with the second or time argument. If you want to use GMT time, you're gonna type time dot GM time. And if you want to work with local time, you're going to put as second argument time dot local time. In this video, I'm going to use just local time function, but GM time function is very similar to it. And now let's say a few words about first argument, which is string format. I'm gonna mention here just a few things about string format and about its directives, but if you want to see a list of all string format directives, you can visit this website stringformattime.org. There you can find full list of string format directives. In this video, I'm going to mention about 10 directives. For example, if you want to use this directive percent A inside your string format, you're gonna get, as the result, abbreviated weekday name. And if you use directive with percent and capital letter A, you're gonna get full weekday name. Let me show you an example. This first argument string format was empty, but now I'm gonna start to populate it with different directives. First, I'm going to use directive percent lowercase letter A, which is going to get abbreviated weekday name. I'm gonna press enter, and we're going to get the abbreviation of Monday. I'm going to copy this full line of code. And now I'm going to use directive with capital letter A, and I'm going to get full name of weekday. Then also, we have directive percent B, which is going to get us abbreviated month name. And if we use percent and capital letter B, we're going to get full month name. I'm gonna show you another example. I'm going to add this directive after this existing A directive in my string format. I'm going to press enter, and we're going to get as a result abbreviations of Monday and July. And I'm going to copy this, and I want to use capital letters. And here we're going to get full weekday name and full month name. Then we have a directive percent D, which is going to give us the day of the month, and that is a number between 1 and 31. Then we have directive percent Y, which is going to get us a year without a century. And that is number between 0 and 99. And we use this directive with capital letter Y. We're going to get a year with century as a decimal number. Let's continue with our example. I'm going to add more and more things to our string format. Now I'm going to add a day. I'm going also to add these slashes to better format our date. Here I'm going to use directive, which is going to return to us the day of the month. I'm going to press enter, and we're going to get that today is July 31. And then also I'm going to use directive for a year to press enter. Now, I don't like to see here July as a word. I would rather see this month as a number. So for month, I'm going to use directive percent M. I'm going to press enter. It's more better. And now I'm going to show you few directives how to get current time. Directive percent H will get us hours as a number between 0 and 23. But if we want to get the hours as a number between 1 and 12, we're going to use directive percent I. For the minutes, we're going to use directive percent M. And we're going to get a number between 0 and 59. And of course, for seconds, we're going to use directive percent S. And also we're going to get number between 0 and 59. And with this directive percent P, we're going to choose if we want to use AM or PA time format. Let's continue with our example. I'm going to copy it. And now we want to add current time. First, I'm going to add the hours. But I want to get hours in this format as a number from 1 to 12. So I'm going to use this directive percent I, then I'm going to get minutes between them. I'm going to use colon sign to get better output. And finally, I'm going to use percent S for seconds and percent P, because in this example, I want to use PM. And now I'm going to press Enter. And here we have a string of current dates and time in a format that we want. That's all in this tutorial. Thanks for watching. Don't forget to subscribe to my channel.