The glass devalues for the calendar date can be represented using the date glass and the date glass
requires three parameters to construct a date.
The year month and date there are two kinds of daytime objects.
One is time zone of it objects and the other time zone uncovered objects handling date times becomes
more complex by dealing with time zones so all of the examples that we are going to discuss that is
the daytime module tutorial odd time zone on orbit objects or nave objects.
So these objects do not contain a Need Time Zone related data if you want to create an instance of the
class you need to give the module name which is date time the dot operator and then the class name attribute
that you need to pass to the date constructor are deal followed by the month and then the date we have
a number of methods defined in the date class that can be used to create instances of the date Class
Day for example.
As we have discussed in the time class we have the replace method that can be used to create a new dead
instance on an existing date.
Let's call this new instance as D2 and we are going to call the replace method on the old instance which
is D 1.
Let's change the year to 2018 for example and lead the month and the date unchanged.
Now let's display D to the new instance and the new one is the old instance.
As with the time values the range of date values supported can be determined using the attribute min
and max no letters or display valid range of values for the date.
And these are the valid range of values for the date object.
Now let us call the desired function and pass the daytime dart date to this function.
Here you can see the various methods that are defined in this class which is the date class.
We will see if your methods defined in this class beginning with the method today and it is easy to
create a date.
Representing today's date using the method to date so let's call this method date daytime dot date dot
today.
Daytime dot day dot today is going to give today's date.
There is another method called seed time which gives the string representation of a date.
So let's call the method seed time on the object D1 and this is a string representation of the date
object D1 the SD out of time.
Method that stands for string format time method can also be applied on date objects.
This method is going to create a string that represents date in a more human readable format.
So let's call this method s.t. out of time and we need to parse a string pattern to this method and
this string pattern explains how we want to format did it.
So let's parse as the string pattern to this method.
So we will first print the year in order to specify the string pattern we are going to refer to the
list of formatting directives.
You can get this list by searching for Python daytime formatting directives on the Internet.
So using this format code that we see here modulo a modulo w etc. We are going to create this string
pattern in order to convert our date object into a string format.
So now let's go back to the Jupiter note book.
So here is the string pattern.
We're now going to execute this cell and see the output.
So here you have a string format or a string representation of Decoded object D1.
Next we will talk about the V DB method let's call the big day method on the object D1 DV day method
calculate the day of the week and it returns a numbered from 0 to 6 where 0 is Monday 1 is Tuesday and
so on and then 6 is Sunday.
So let's execute this.
So that means this day that is the 21st of July 2019 is a Sunday.
Let's call this method on the object to do and this has returned 5 which means it is a Saturday.
Next is the time tuple method before discussing about this method.
We need to discuss about struct time object the date time module defined struct time object and it is
used for holding.
Date and time values with the component broken out.
So that easy to access and destruct time object has nine attributes for representing a point in time
these track time object is represented as a tuple of date and time element.
As you can see there are nine attributes that are defined in this object.
So for example we have the year month day representing the data object and then we had the R word minute.
Second big day day of the year and then the daylight saving time.
Let us call the time tuple method on the date object.
So here we have the date and the time values broken down for easy access.
Next is the from timestamp method the from timestamp method returns the date and the time for the provided
timestamp.
So let us call the timestamp method.
Daytime doe date dot from timestamp and to this method we are going to pass the UNIX timestamp as we
know the UNIX timestamp is a number of seconds that have passed since the first of January nineteen
seventy.
So let's say we are going to pass the while you do timestamp 0 and then execute so the timestamp zero
refers to the Unix epoch time as we have discussed during the time class.
No let us pass another value to the method from timestamp daytime dot day dot from timestamp.
So let us pass an arbitrary number of seconds to this method and then execute and this value of the
timestamp.
That is the number of second reference to this calendar date.
The daytime class in the daytime module a daytime object is a single object containing all of the information
from our date object and a time object.
So the daytime object is a combination of date and time objects.
So the date time on object takes the attribute you'd month day from the date object and then the R word
minute second microsecond from the time object and when you're creating a daytime object from the daytime
constructor the first three attribute that is the year month and day are mandatory.
Let us now create a daytime object.
Let us pass the year and then the month day and also daytime values tell Rosie a word 45 is a minute
and then the seconds and then D2 1 is the daytime object.
Now you can separate the date portion from the time portion and ignore daytime portion by calling the
date method on this object DTA 1.
So let's execute this.
So here you have the date object derived from the daytime object.
Similarly you can separate the time portion from the date time object.
For that you need to call the method time on the object DG 1.
And here you have derived the time object from the date time object.
DG 1.
Now in order to see these various methods defined in this class date time let's call the desired function.
And these are the various methods defined in this class.
Now let's discuss some of the important methods in the class.
Let's begin with the method today.
Daytime DOD daytime dot today this method is going to return a daytime object but today's date and time
the next method that we're going to call is now and this method also creates a daytime instance with
we decoded time and date but the value returned by this method now is more precise than the value returned
by this method today.
Next we will call the UTC no method.
The UTC now method is going to return the current UTC time.
Next is the from timestamp method and this is going to return the date and time for the provided timestamp.
Let's say this is the timestamp and then execute the cell.
And this is the date and time for the given time stamp.
Next we will talk about the is D R P time DST R P time that stands for String part time is a method
that is capable of passing a string containing date and produce a daytime object.
We have discussed about these d out of time which convert or time object or a date object into a string
format the SD out big time the string pass time goes in the opposite direction.
So in order to understand this let's see an example when you call the is the RB time you need to pass
the data string which is a string representation of the daytime object and also the format string.
Both of these arguments are mandatory.
The format parameter uses the same formatting directives as those used by the SD out of time method.
So now let's look at an example in the Jupiter note book.
So we have taught that the method C time gives these string representation of a daytime object.
So I have called this method C time on the daytime object D 1 and now one is a string representation
of the daytime object.
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
to this method we are going to parse the data string as one and we also need to parse a string that
represent the format let us pass the string to the SD RB time and this format parameter has been generated
by referring to the formatting directives list that we have seen before.
No let's execute this cell.
And here you have the daytime object from the SD RB time method we have seen two methods.
First is the date method which extracts d date portion from the daytime object and then we have seen
the time method which extracts daytime portion from the daytime object.
We have another method defined in the daytime class which is the combine method and this method create
a daytime object by combining a data object and a time object so letters combine the date object D 1
and the time object T1 daytime DOD daytime dart combine.
We need to specify the date object followed by the time object independent sources and then execute.
So here we have a daytime object which has the date attributes from the date object and the time attribute
from the time object.