1 00:00:00,090 --> 00:00:08,520 The glass devalues for the calendar date can be represented using the date glass and the date glass 2 00:00:08,610 --> 00:00:12,650 requires three parameters to construct a date. 3 00:00:12,660 --> 00:00:19,840 The year month and date there are two kinds of daytime objects. 4 00:00:19,880 --> 00:00:30,290 One is time zone of it objects and the other time zone uncovered objects handling date times becomes 5 00:00:30,380 --> 00:00:39,250 more complex by dealing with time zones so all of the examples that we are going to discuss that is 6 00:00:39,250 --> 00:00:47,570 the daytime module tutorial odd time zone on orbit objects or nave objects. 7 00:00:47,590 --> 00:00:57,160 So these objects do not contain a Need Time Zone related data if you want to create an instance of the 8 00:00:57,160 --> 00:01:07,160 class you need to give the module name which is date time the dot operator and then the class name attribute 9 00:01:07,220 --> 00:01:16,880 that you need to pass to the date constructor are deal followed by the month and then the date we have 10 00:01:16,880 --> 00:01:24,260 a number of methods defined in the date class that can be used to create instances of the date Class 11 00:01:24,270 --> 00:01:25,760 Day for example. 12 00:01:25,760 --> 00:01:33,860 As we have discussed in the time class we have the replace method that can be used to create a new dead 13 00:01:33,920 --> 00:01:36,200 instance on an existing date. 14 00:01:36,210 --> 00:01:44,660 Let's call this new instance as D2 and we are going to call the replace method on the old instance which 15 00:01:44,660 --> 00:01:45,580 is D 1. 16 00:01:45,590 --> 00:01:53,300 Let's change the year to 2018 for example and lead the month and the date unchanged. 17 00:01:53,300 --> 00:01:59,320 Now let's display D to the new instance and the new one is the old instance. 18 00:01:59,360 --> 00:02:06,650 As with the time values the range of date values supported can be determined using the attribute min 19 00:02:06,800 --> 00:02:12,590 and max no letters or display valid range of values for the date. 20 00:02:12,590 --> 00:02:16,430 And these are the valid range of values for the date object. 21 00:02:16,430 --> 00:02:25,520 Now let us call the desired function and pass the daytime dart date to this function. 22 00:02:25,520 --> 00:02:32,000 Here you can see the various methods that are defined in this class which is the date class. 23 00:02:32,030 --> 00:02:38,750 We will see if your methods defined in this class beginning with the method today and it is easy to 24 00:02:38,750 --> 00:02:40,210 create a date. 25 00:02:40,340 --> 00:02:49,480 Representing today's date using the method to date so let's call this method date daytime dot date dot 26 00:02:49,500 --> 00:02:49,890 today. 27 00:02:50,120 --> 00:02:55,070 Daytime dot day dot today is going to give today's date. 28 00:02:55,180 --> 00:03:01,980 There is another method called seed time which gives the string representation of a date. 29 00:03:02,060 --> 00:03:10,970 So let's call the method seed time on the object D1 and this is a string representation of the date 30 00:03:11,030 --> 00:03:14,230 object D1 the SD out of time. 31 00:03:14,240 --> 00:03:21,680 Method that stands for string format time method can also be applied on date objects. 32 00:03:21,680 --> 00:03:28,610 This method is going to create a string that represents date in a more human readable format. 33 00:03:28,640 --> 00:03:37,100 So let's call this method s.t. out of time and we need to parse a string pattern to this method and 34 00:03:37,100 --> 00:03:42,070 this string pattern explains how we want to format did it. 35 00:03:42,140 --> 00:03:46,310 So let's parse as the string pattern to this method. 36 00:03:46,310 --> 00:03:52,910 So we will first print the year in order to specify the string pattern we are going to refer to the 37 00:03:53,270 --> 00:03:55,800 list of formatting directives. 38 00:03:55,820 --> 00:04:02,180 You can get this list by searching for Python daytime formatting directives on the Internet. 39 00:04:02,300 --> 00:04:11,150 So using this format code that we see here modulo a modulo w etc. We are going to create this string 40 00:04:11,150 --> 00:04:16,970 pattern in order to convert our date object into a string format. 41 00:04:17,000 --> 00:04:20,030 So now let's go back to the Jupiter note book. 42 00:04:20,030 --> 00:04:23,310 So here is the string pattern. 43 00:04:23,510 --> 00:04:27,690 We're now going to execute this cell and see the output. 44 00:04:27,710 --> 00:04:34,550 So here you have a string format or a string representation of Decoded object D1. 45 00:04:34,550 --> 00:04:43,400 Next we will talk about the V DB method let's call the big day method on the object D1 DV day method 46 00:04:43,430 --> 00:04:53,210 calculate the day of the week and it returns a numbered from 0 to 6 where 0 is Monday 1 is Tuesday and 47 00:04:53,210 --> 00:04:56,690 so on and then 6 is Sunday. 48 00:04:56,960 --> 00:04:59,120 So let's execute this. 49 00:04:59,270 --> 00:05:05,810 So that means this day that is the 21st of July 2019 is a Sunday. 50 00:05:05,810 --> 00:05:13,730 Let's call this method on the object to do and this has returned 5 which means it is a Saturday. 51 00:05:13,730 --> 00:05:18,720 Next is the time tuple method before discussing about this method. 52 00:05:18,740 --> 00:05:28,220 We need to discuss about struct time object the date time module defined struct time object and it is 53 00:05:28,220 --> 00:05:29,420 used for holding. 54 00:05:29,450 --> 00:05:34,640 Date and time values with the component broken out. 55 00:05:34,640 --> 00:05:43,430 So that easy to access and destruct time object has nine attributes for representing a point in time 56 00:05:43,790 --> 00:05:50,950 these track time object is represented as a tuple of date and time element. 57 00:05:51,080 --> 00:05:56,030 As you can see there are nine attributes that are defined in this object. 58 00:05:56,030 --> 00:06:07,230 So for example we have the year month day representing the data object and then we had the R word minute. 59 00:06:07,340 --> 00:06:13,940 Second big day day of the year and then the daylight saving time. 60 00:06:14,120 --> 00:06:19,080 Let us call the time tuple method on the date object. 61 00:06:19,100 --> 00:06:26,260 So here we have the date and the time values broken down for easy access. 62 00:06:26,360 --> 00:06:36,380 Next is the from timestamp method the from timestamp method returns the date and the time for the provided 63 00:06:36,590 --> 00:06:37,900 timestamp. 64 00:06:37,940 --> 00:06:41,530 So let us call the timestamp method. 65 00:06:43,300 --> 00:06:55,040 Daytime doe date dot from timestamp and to this method we are going to pass the UNIX timestamp as we 66 00:06:55,040 --> 00:07:04,390 know the UNIX timestamp is a number of seconds that have passed since the first of January nineteen 67 00:07:04,440 --> 00:07:05,420 seventy. 68 00:07:05,420 --> 00:07:16,330 So let's say we are going to pass the while you do timestamp 0 and then execute so the timestamp zero 69 00:07:16,420 --> 00:07:23,370 refers to the Unix epoch time as we have discussed during the time class. 70 00:07:23,380 --> 00:07:34,090 No let us pass another value to the method from timestamp daytime dot day dot from timestamp. 71 00:07:34,810 --> 00:07:44,860 So let us pass an arbitrary number of seconds to this method and then execute and this value of the 72 00:07:44,860 --> 00:07:45,790 timestamp. 73 00:07:45,790 --> 00:07:51,710 That is the number of second reference to this calendar date. 74 00:07:52,000 --> 00:08:02,500 The daytime class in the daytime module a daytime object is a single object containing all of the information 75 00:08:02,500 --> 00:08:06,540 from our date object and a time object. 76 00:08:06,610 --> 00:08:16,040 So the daytime object is a combination of date and time objects. 77 00:08:16,150 --> 00:08:28,600 So the date time on object takes the attribute you'd month day from the date object and then the R word 78 00:08:28,990 --> 00:08:38,980 minute second microsecond from the time object and when you're creating a daytime object from the daytime 79 00:08:38,980 --> 00:08:47,500 constructor the first three attribute that is the year month and day are mandatory. 80 00:08:47,500 --> 00:08:51,190 Let us now create a daytime object. 81 00:08:51,190 --> 00:09:05,490 Let us pass the year and then the month day and also daytime values tell Rosie a word 45 is a minute 82 00:09:05,580 --> 00:09:11,220 and then the seconds and then D2 1 is the daytime object. 83 00:09:11,220 --> 00:09:20,310 Now you can separate the date portion from the time portion and ignore daytime portion by calling the 84 00:09:20,820 --> 00:09:24,710 date method on this object DTA 1. 85 00:09:24,840 --> 00:09:26,250 So let's execute this. 86 00:09:26,250 --> 00:09:32,070 So here you have the date object derived from the daytime object. 87 00:09:32,070 --> 00:09:40,850 Similarly you can separate the time portion from the date time object. 88 00:09:41,130 --> 00:09:46,330 For that you need to call the method time on the object DG 1. 89 00:09:46,440 --> 00:09:52,610 And here you have derived the time object from the date time object. 90 00:09:52,640 --> 00:09:53,600 DG 1. 91 00:09:53,700 --> 00:10:02,640 Now in order to see these various methods defined in this class date time let's call the desired function. 92 00:10:02,700 --> 00:10:07,710 And these are the various methods defined in this class. 93 00:10:07,710 --> 00:10:12,590 Now let's discuss some of the important methods in the class. 94 00:10:12,630 --> 00:10:15,580 Let's begin with the method today. 95 00:10:16,260 --> 00:10:26,400 Daytime DOD daytime dot today this method is going to return a daytime object but today's date and time 96 00:10:26,760 --> 00:10:35,040 the next method that we're going to call is now and this method also creates a daytime instance with 97 00:10:35,070 --> 00:10:43,440 we decoded time and date but the value returned by this method now is more precise than the value returned 98 00:10:43,740 --> 00:10:46,240 by this method today. 99 00:10:46,470 --> 00:10:51,450 Next we will call the UTC no method. 100 00:10:51,450 --> 00:10:57,390 The UTC now method is going to return the current UTC time. 101 00:10:57,690 --> 00:11:07,320 Next is the from timestamp method and this is going to return the date and time for the provided timestamp. 102 00:11:07,740 --> 00:11:14,020 Let's say this is the timestamp and then execute the cell. 103 00:11:14,460 --> 00:11:19,110 And this is the date and time for the given time stamp. 104 00:11:19,110 --> 00:11:30,840 Next we will talk about the is D R P time DST R P time that stands for String part time is a method 105 00:11:30,870 --> 00:11:37,750 that is capable of passing a string containing date and produce a daytime object. 106 00:11:37,800 --> 00:11:45,900 We have discussed about these d out of time which convert or time object or a date object into a string 107 00:11:45,900 --> 00:11:52,640 format the SD out big time the string pass time goes in the opposite direction. 108 00:11:52,950 --> 00:12:00,000 So in order to understand this let's see an example when you call the is the RB time you need to pass 109 00:12:00,000 --> 00:12:09,900 the data string which is a string representation of the daytime object and also the format string. 110 00:12:10,050 --> 00:12:13,170 Both of these arguments are mandatory. 111 00:12:13,380 --> 00:12:22,880 The format parameter uses the same formatting directives as those used by the SD out of time method. 112 00:12:22,920 --> 00:12:26,610 So now let's look at an example in the Jupiter note book. 113 00:12:26,610 --> 00:12:36,360 So we have taught that the method C time gives these string representation of a daytime object. 114 00:12:36,360 --> 00:12:47,100 So I have called this method C time on the daytime object D 1 and now one is a string representation 115 00:12:47,250 --> 00:12:48,670 of the daytime object. 116 00:12:48,670 --> 00:13:01,990 D d 1 let's call the method SD RB time string part time so date time dot day time dot SD B time end 117 00:13:02,010 --> 00:13:11,310 to this method we are going to parse the data string as one and we also need to parse a string that 118 00:13:11,310 --> 00:13:22,170 represent the format let us pass the string to the SD RB time and this format parameter has been generated 119 00:13:22,170 --> 00:13:29,130 by referring to the formatting directives list that we have seen before. 120 00:13:29,160 --> 00:13:31,920 No let's execute this cell. 121 00:13:32,550 --> 00:13:42,120 And here you have the daytime object from the SD RB time method we have seen two methods. 122 00:13:42,120 --> 00:13:50,070 First is the date method which extracts d date portion from the daytime object and then we have seen 123 00:13:50,070 --> 00:13:57,840 the time method which extracts daytime portion from the daytime object. 124 00:13:57,840 --> 00:14:07,680 We have another method defined in the daytime class which is the combine method and this method create 125 00:14:07,800 --> 00:14:20,220 a daytime object by combining a data object and a time object so letters combine the date object D 1 126 00:14:20,400 --> 00:14:29,360 and the time object T1 daytime DOD daytime dart combine. 127 00:14:29,580 --> 00:14:40,230 We need to specify the date object followed by the time object independent sources and then execute. 128 00:14:40,230 --> 00:14:48,780 So here we have a daytime object which has the date attributes from the date object and the time attribute 129 00:14:48,780 --> 00:14:50,920 from the time object.