Date & Time

6 minutes
Share the link to this page
Copied
  Completed
A Python program can handle date and time in several ways. Converting between date formats is a common chore for computers. Python's time and calendar modules help track dates and times

Transcript

Hello in this video we are going to cover date and time and pi phi handled date and time is several ways. And yeah, so let's start with this. So first of all we need to import the time module. So to import the time module import time, like so. And now if we do something like what is row one equals 2.9 and now let's print the contents of wall one see what we get. Okay, so we got this value you might thinking, Okay, what is value?

How does it matter? And well, it's essentially referred to as ticks. And if the number of ticks since epoch, time and epoch time is widely considered in as 12am, first of January 1970. And that's it really not much more to it than they might think. And why would ever need to use it? If you're trying to keep track of something, you know, epoch is a great thing to use, because you know, you know exactly where when it started, you know, the exact time date.

So if you're trying to work out how much time has passed, let's say, if you click a button, and you click the button, how much time passed between the two clicks? Well, it just be the difference between the first epoch and the second both are giving you the exact tick command. And on top of that, you can you know, convert that to seconds, you can convert it to minute, hour days, etc, cetera. So what else do we have? What else tip here. So there is also stuff called time to pause, we can get the current time.

So let's look at getting the current time. So the current time is pretty easy. Obviously, make sure you have the import time module. And if we have to say, no local time to dot local and we need to specify the parameter as well. Let's create a local run it so yeah, run has now actually be module time naturally local time. lowercase t programming a programming.

So there we go. It says it is 2018 which is it says the month, fifth month, which is you know, January February March April, May 5 month yes to 17. And now give you now's the time. So 1333 35 I think knew why the a bit off is just due to daylight savings. But that gives you the time and obviously you can manipulate that further and just accept individual values. So you can also do stuff like get formatted time, if we get formatted time.

So if we do time, local and assign it to the value of time at C ASC time got no cool Specify the parameter, we need an extra bracket print on local. And let's have a look at what we get. There we go. This is a slightly more formatted version of a lot more readable than this. So, what else can we do we can you know get calendar for a month a lot so, that we need to do in the report for you to do generally imports are just at the top of the page import this would be just label and this is time we are going to do so first of all This creates a calendar variable. And I set it to calendar, dot month.

And let's see if we did 2008. And we specified one. So what do you think you're going to get with this? What you're going to try and pause the video, try and take this and let's have a look. There we go. We literally get the calendar for the month of January 2019.

I'll be thinking, why do we specify the year because, well, you know, you get a certain month like February that could you know, change in terms of the amount of data that depending on whether it's a leap year. So that's the main reason why and the other reason is the first of January was on Tuesday in development, but he won't be on to the interval seven or nine. So he also for that memory Well, so we let's have a look at the time module has, you know, so many functions. It has a clock function at that local time function, sleep function time function. It has, you know, alternative zone functions. The calendar module has only function that checks if you're the lead PA, if it's the first day of the week and month calendar, there's so many extra modules and functions.

We've covered a few of them. And what we've covered here is enough to get you started. If you understand what we've done in this video, you're all good to go. I'll provide a link with this video so you can actually enhance your experience and actually check out the other features as well. Thank you for watching, and I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.