1 00:00:02,910 --> 00:00:07,170 Hello welcome to this tutorial on the daytime module 2 00:00:09,850 --> 00:00:21,450 the daytime module provides classes and functions to work with times date and time maintenance and the 3 00:00:21,510 --> 00:00:31,110 daytime module as part of the python's Standard Library which means we do not have to install it separately. 4 00:00:31,240 --> 00:00:41,230 We can simply import as he's into our programs and these are some of the classes that we are going to 5 00:00:41,230 --> 00:00:44,160 discuss in this tutorial time. 6 00:00:45,390 --> 00:00:49,410 Date date time and time. 7 00:00:49,470 --> 00:00:57,500 Delta Python provides a variety of time and date processing methods. 8 00:00:57,510 --> 00:01:09,060 In the daytime module and these are the classes that are defined in the daytime module time date date 9 00:01:09,120 --> 00:01:17,750 time and time Delta and each of these classes define a number of methods or functions that can be used 10 00:01:17,750 --> 00:01:22,010 to manipulate date time and time intervenes. 11 00:01:22,130 --> 00:01:37,930 Say for example the time class defines the method IE is so format and and the method as these are if 12 00:01:37,940 --> 00:01:48,470 time both of these methods can be used to give a string representation of the time instance the object 13 00:01:48,800 --> 00:01:57,940 that is created using daytime class we will see various methods when we have a detailed discussion on 14 00:01:58,030 --> 00:02:05,710 each of these classes before discussing about the classes defined in the daytime module. 15 00:02:05,710 --> 00:02:15,550 We need to understand some basic terms beginning with timestamp a timestamp is the current time of an 16 00:02:15,640 --> 00:02:19,140 event that is recorded by a computer. 17 00:02:19,330 --> 00:02:28,390 Say for example of a computer files contain timestamps that tell us when the file was last created or 18 00:02:28,660 --> 00:02:40,060 modified timestamp is a sequence of characters or encoded information identifying when a certain event 19 00:02:40,060 --> 00:02:50,110 has occurred and the timestamp usually gives the date and time of the day when the event has occurred. 20 00:02:50,170 --> 00:02:54,040 Sometimes accurate to a small fraction of a second. 21 00:02:54,430 --> 00:03:05,280 And these are some of the different format in which timestamps can be represented next unix time unix 22 00:03:05,280 --> 00:03:10,350 time is also known as politics time or Unix epoch. 23 00:03:10,350 --> 00:03:20,940 Time is a system for describing a point in time and also the UNIX timestamp is the number of seconds 24 00:03:22,710 --> 00:03:26,390 from some arbitrary point in the past. 25 00:03:26,490 --> 00:03:39,040 And for Unix systems it is the first of January 1970 UDC epoch is nothing but an instant of time or 26 00:03:39,130 --> 00:03:45,310 a date selected as a point of reference for Unix systems. 27 00:03:45,310 --> 00:03:55,600 This is the date which has been chosen as the epoch time which is the midnight of the first of January 28 00:03:55,990 --> 00:04:05,150 nineteen seventy and what is the Unix epoch time used for this timestamp or the Unix epoch. 29 00:04:05,140 --> 00:04:13,600 Time is used by the computer to tell the time and the date timestamp for the Unix epoch time is marked 30 00:04:13,750 --> 00:04:29,380 as zero and today's date is is July 4th 2000 19 and a need time since this date is calculated based 31 00:04:29,380 --> 00:04:32,690 on the number of seconds elapsed. 32 00:04:32,710 --> 00:04:42,010 So in simple words the time stamp of the Fourth of July 2019 will be the difference in seconds between 33 00:04:42,130 --> 00:04:48,850 this date and the first of January nineteen seventy. 34 00:04:48,850 --> 00:05:01,990 So basically the computer tells the time by keeping a count of each passing second since the first of 35 00:05:01,990 --> 00:05:07,800 January nineteen seventy and this is stored as an integer. 36 00:05:08,080 --> 00:05:19,600 So the e-book reference date is a point on the timeline from which we count time and moments before 37 00:05:19,630 --> 00:05:21,040 this time. 38 00:05:21,040 --> 00:05:24,970 That is the epoch time are counted with a negative number. 39 00:05:25,210 --> 00:05:32,070 And moments after are counted with a positive number. 40 00:05:32,260 --> 00:05:35,860 Also there are many e-books in use today. 41 00:05:35,950 --> 00:05:42,670 So for example for the Windows systems the e-book time is the first of January. 42 00:05:42,670 --> 00:05:45,330 Sixteen hundred and four Mac systems. 43 00:05:45,340 --> 00:05:51,600 It is the first of January nineteen hundred and for the next term that we're going to talk about of 44 00:05:51,600 --> 00:06:06,790 the ISO 8 6 0 1 format the ISO 8 6 0 1 standardize is the representation of date and times and these 45 00:06:06,790 --> 00:06:17,760 standard representations are used to construct timestamp values and also this standard the ISO 8 6 0 46 00:06:17,760 --> 00:06:25,950 1 provide an extensive set of practically well designed for months for expressing the date and time 47 00:06:25,950 --> 00:06:36,780 values as text and these four months are easy to pass by machines as well as easy to read by humans 48 00:06:36,900 --> 00:06:48,360 across cultures and these are some of the ISO 8 6 0 1 date and time formats the next term is coordinated 49 00:06:48,450 --> 00:06:59,910 Universal Time UTC UTC is the time standard commonly used across the world and the world's timing centres 50 00:07:00,090 --> 00:07:09,000 have agreed to keep their timescales closely synchronized or coordinated and hence the name coordinated 51 00:07:09,120 --> 00:07:20,710 Universal Time and UTC or the coordinated Universal Time is a standard and not a time zone and it is 52 00:07:20,710 --> 00:07:28,210 the base point for all other time zones in the world and if you want to determine the time zone of a 53 00:07:28,210 --> 00:07:36,940 particular region it can be determined by its different to the UDC and UTC is represented like this 54 00:07:38,020 --> 00:07:47,390 the Unix or deposits timestamps that we discussed before are always based on UTC we will now discuss 55 00:07:47,390 --> 00:07:56,300 the various classes defined in the daytime module beginning with the time plus the time values are represented 56 00:07:56,300 --> 00:08:05,300 with the timed class and the timed class provide access to where it is time related methods or functions 57 00:08:06,170 --> 00:08:17,960 and it has the R word minute second microsecond as D attributes in order to create an instance or an 58 00:08:17,960 --> 00:08:25,730 object of the time plus we need to access the time class defined in the daytime module using the dot 59 00:08:25,850 --> 00:08:35,630 operator so the time class can be accessed using did DOD operate like this. 60 00:08:35,680 --> 00:08:36,960 Date time. 61 00:08:36,970 --> 00:08:47,200 The module name and the last name is time separated by the dot operator and the time class has the attribute 62 00:08:47,610 --> 00:09:00,150 of it minute seconds and then microseconds and this is going to create a time object and the arguments 63 00:09:00,180 --> 00:09:08,520 to initialize a time instance are an object add option in if the arguments are not provided a default 64 00:09:08,580 --> 00:09:15,150 of 0 is assumed in order to create an instance of an object of the time. 65 00:09:15,150 --> 00:09:23,070 Class B would have to first import the daytime module so let's import the daytime module using the import 66 00:09:23,070 --> 00:09:30,890 statement now we can access the different classes using the dot operator. 67 00:09:31,020 --> 00:09:40,590 So let us suppose to create an instance of the time class let's call this instance D one daytime dot 68 00:09:40,590 --> 00:09:55,520 time and let's pass the arguments for the other word and then minutes seconds and then execute the same 69 00:09:56,220 --> 00:09:57,410 lit display. 70 00:09:58,970 --> 00:10:11,200 The object to 1 T 1 is an object of the date time dot time class and here are these values for each 71 00:10:11,260 --> 00:10:12,910 of the attributes. 72 00:10:13,000 --> 00:10:21,940 We can also create new time objects by using the replace method on an existing time object. 73 00:10:21,940 --> 00:10:23,840 So how does this work. 74 00:10:23,860 --> 00:10:35,180 So let's call our new instance as D2 and this is being created from the old instance T1. 75 00:10:35,560 --> 00:10:44,320 We need to call the replace method on the old instance in order to create new instance of the new object 76 00:10:44,710 --> 00:10:46,880 and to this replace method. 77 00:10:46,960 --> 00:10:55,350 We need to parse new while used for the R word minute and second attribute. 78 00:10:55,420 --> 00:11:03,580 If you do not pass any values to any of the attribute that remains the attribute value remains unchanged. 79 00:11:03,580 --> 00:11:12,580 Say for example I only want to change the attribute of what the value is going to be twenty three the 80 00:11:12,580 --> 00:11:16,170 arguments minute and second remain unchanged. 81 00:11:16,510 --> 00:11:20,460 So let's display the objects too. 82 00:11:21,550 --> 00:11:30,100 So as you can see new value for the I would attribute 23 has been assigned to this time object T to 83 00:11:31,110 --> 00:11:41,980 and let us also display the object T 1 and the values for this object are not changed. 84 00:11:41,980 --> 00:11:51,390 Let us now see the valid range of values for a time object using the minimum and maximum. 85 00:11:51,400 --> 00:11:53,620 Class attributes. 86 00:11:53,620 --> 00:12:03,250 So in order to call these attributes let's use the dot operator daytime dot time dot Min 87 00:12:05,860 --> 00:12:09,040 so these are the minimum. 88 00:12:09,040 --> 00:12:17,050 Let us now see the maximum values that can be assigned to the time object and these are the maximum 89 00:12:17,050 --> 00:12:26,430 values that can be assigned to a time object and then you can display each of the attributes the individual 90 00:12:26,460 --> 00:12:34,100 attributes like upward minute second on time object by using the dot operator. 91 00:12:34,110 --> 00:12:41,790 So this is how you display the individual attributes if you want to represent your day time or time 92 00:12:41,850 --> 00:12:52,440 object in a string format you can call the method ISO format on the daytime or time object so let's 93 00:12:52,440 --> 00:13:00,880 call the yes so format method on the object. 94 00:13:00,950 --> 00:13:11,750 D 1 and this is how the ISO 8 6 0 1 represents the time object in the form of a string. 95 00:13:11,870 --> 00:13:19,340 If you want to know the various methods or attribute that that are defined on a date time or time object 96 00:13:20,360 --> 00:13:30,440 you can use the desired function and pass day time dot time to the desired function and then execute. 97 00:13:30,440 --> 00:13:38,630 And here you have the various functions and attributes that are defined in the time class. 98 00:13:38,690 --> 00:13:46,370 We can also compare time values using these standard operators in order to determine which is earlier 99 00:13:46,490 --> 00:13:59,130 odd later so let's compare these two objects D1 and D2 using the greater than operator so t1 is less 100 00:13:59,130 --> 00:14:08,870 than T2 and this is returned to let us now discuss another method defined in a time class which is s.t. 101 00:14:08,880 --> 00:14:16,290 out of time method which stands for string format time method. 102 00:14:16,290 --> 00:14:26,290 This method allows us to create a string that represents a time in a more human readable format. 103 00:14:26,670 --> 00:14:37,560 So let us say we want to create a string and output string in this format from the daytime dot time 104 00:14:37,620 --> 00:14:38,650 object. 105 00:14:38,780 --> 00:14:44,090 D 1 and we need to parse a string. 106 00:14:45,410 --> 00:14:55,310 To the method is t r f time say for example this string in school if we need to parse a string pattern 107 00:14:55,310 --> 00:15:04,730 to this method s.t. out of time and this string pattern explained how we need to format our time object 108 00:15:05,600 --> 00:15:09,020 so let's first create a string pattern. 109 00:15:09,860 --> 00:15:19,100 So here I have created a string pattern which explains the method SDR a time how the output string should 110 00:15:19,100 --> 00:15:21,860 be represented in string format. 111 00:15:21,860 --> 00:15:31,370 Now we have called the SDR of time on the object T 1 and have passed this string pattern variable. 112 00:15:31,370 --> 00:15:41,980 Now when the estimate of time method read the string pattern or the format it encounters this operator 113 00:15:42,070 --> 00:15:51,910 modulo and when this method encounters the modulo operator it knows that it needs to replace the modulo 114 00:15:51,910 --> 00:15:59,240 operator along with the letter following the operator with a certain code. 115 00:15:59,240 --> 00:16:09,010 Odd also known as a format code and here is a list of format quotes which are used by SDR of time method 116 00:16:09,280 --> 00:16:13,360 to return a String based on these codes. 117 00:16:13,360 --> 00:16:22,420 Say for example we want to print the value of the R word attribute from the daytime die time object 118 00:16:23,170 --> 00:16:24,830 in the output string. 119 00:16:24,850 --> 00:16:32,180 So in that case we need to use the modulo hedge format called the modulo hedge. 120 00:16:32,290 --> 00:16:41,410 Court gives these others as a zero padded decimal number like this and then in order to display the 121 00:16:41,410 --> 00:16:50,410 minute in the output string we use the modulo M chord and this gives the minute as a zero by the decimal 122 00:16:50,500 --> 00:16:58,020 number and then modulo s in order to display these seconds as a zero padded decimal number. 123 00:16:58,390 --> 00:17:05,710 So let's see an example in the Jupiter notebook which uses these format codes to convert daytime or 124 00:17:05,710 --> 00:17:08,070 time object into a string. 125 00:17:08,110 --> 00:17:18,700 No let's call the SD ata time method on the object T 1 in order to display this object in a human readable 126 00:17:18,700 --> 00:17:21,710 format to the SD out of time method. 127 00:17:21,790 --> 00:17:25,920 We need to pass a format or a string pattern. 128 00:17:26,020 --> 00:17:33,400 So in this pattern we are going to separate the different attribute the hour minute and seconds with 129 00:17:33,520 --> 00:17:34,100 a colon. 130 00:17:34,570 --> 00:17:43,970 So in order to first display the others we are going to use the DB format called modulo H which is going 131 00:17:43,970 --> 00:17:51,800 to display the others in the object and then this is separated with a colon and then we're going to 132 00:17:51,800 --> 00:18:02,930 display the minute using the format called modulo M and then this is separated by a colon. 133 00:18:02,930 --> 00:18:10,170 And finally we're going to display the second which is represented by modulo s. 134 00:18:10,380 --> 00:18:14,190 Now let's execute this line. 135 00:18:14,190 --> 00:18:23,540 So now we have the obvious minutes and second displayed in the form of a string and calling the SD out 136 00:18:23,540 --> 00:18:27,060 of time method on the daytime long time object. 137 00:18:27,230 --> 00:18:28,680 Create a new string. 138 00:18:28,820 --> 00:18:32,120 And it does not affect the object. 139 00:18:32,120 --> 00:18:36,530 And here we have these object daytime dot time.