‫Welcome back.
‫In this video, you will learn about daytime, which allows us to use time and to get the time to get
‫a difference between a specific date and another date and so forth.
‫And therefore, we just need to use the daytime class and the daytime class is automatically available
‫if you have the system namespace included, which is the case pretty much in any program that we're
‫using.
‫Right?
‫So let's go ahead and use date time and create a date time object.
‫So I'm going to call that object date time and it's called date time because it not only gives us the
‫date, but it also gives us the time.
‫So it gives us all the information about a date and time up to the milliseconds.
‫So let's go ahead and create a date time object, which we did here.
‫And now we initialize it.
‫And let's say I want to only have the year, month and day, then I can just enter something like 22,
‫18, five and 31, which is my birthday or was my birthday this year.
‫So I'm using that in order to find out how many days I've lived.
‫For example, we will write a little program later on which will tell us how many days we've been on
‫this earth.
‫Which is pretty interesting because I looked into how many days I've lived, and I figured out that
‫very soon I'm going to be 11,111 days old.
‫And finally, a friend of mine, a very good friend from childhood, he will be 11,111 days old on the
‫11th of November.
‫And in Cologne, where I come from, Carnival is pretty big and it starts on 11th at 11:00 and 11 minutes.
‫So that's on in November.
‫So it's pretty funny that he has this very crazy date pretty much for his 11,111th day.
‫So maybe you figured out what the interesting date for you is.
‫A very cool day for you is to celebrate so you won't only celebrate your birthday, but maybe also your
‫10,000 stay or your 15,000 day on earth or however old you are.
‫So maybe you figured something out.
‫All right, enough side talk.
‫Let's get back to date time.
‫So I have created this little data time object, and now I can write something onto the console and
‫I'm going to say something like my birthday is and I enter the birthday here and what do I give over
‫or hand over?
‫I give over my date time object.
‫Now, my birthday this year was in 2018, but I was born in 1988.
‫So if I want to be more precise, of course I have to enter that.
‫All right, so let's run it control f five in order to run this application and keep it open that we
‫are my birthday is and that you see that the structure is 531, 2001 1988.
‫And then it even gives us the hour, minute and second and am here.
‫So we didn't specify that, but it gives all this information because we asked for the date time and
‫it contains this information even though we didn't specify it ourselves.
‫And if we create a date time object, let me go back here, then we can go ahead and have multiple different
‫overloads.
‫So let me create one.
‫As you can see, there are eight overloads, so one which is just an empty date time.
‫Then we have one with long ticks and ticks, a date and date and time expressed.
‫And the number of 100 nanosecond intervals.
‫Then we have to date time kind.
‫So you can also define the kind of data time that you have in year and month and then date.
‫That's the one that we used.
‫Then you can also specify the hour, minute and second and also the date time kind.
‫Here as well and the different overload.
‫And here you can even go as far as specifying the millisecond and finally, also with the date time
‫kind.
‫Now you might wonder what this daytime kind is.
‫And it's a property which gets a value that indicates whether the time represented by the instance is
‫based on local time, coordinated, universal time UTC or which is called UTC or neither.
‫All right.
‫So let's get back to our example and I'm going to enter or I'm going to go back to my values that I
‫had here.
‫And now I'm going to show you how you can display the current date.
‫So right today on screen.
‫So if you want to have the date of today, you can simply use date time dot today.
‫But that will do is it will give you the current date.
‫So let's run that again.
‫Controller five There we are.
‫Today is the 12th of June and well, the time is not correct here, but well it still has the current
‫time or it still has the time in here if you want to have the specific time.
‫So right current time on screen then you use date time dot now so there's this property gets daytime
‫object that is set to the current date and time on this computer expressed as local time.
‫And let me run it again.
‫And there you are.
‫It's one 5030 5 p.m..
‫All right.
‫So if you want to display the current time or the time that is specified on the computer in your application
‫or in your program, you can simply use date time.
‫Dot Now.
‫Now, you also can get the day of tomorrow, so you can get the following day, but therefore you need
‫to create a little workaround.
‫So there is no property which says tomorrow, let's check it out.
‫Date time dot tomorrow.
‫As you can see, it doesn't have that it has to date and you can generally check out which properties
‫there are now, today and UTC now, which is this kind that I've just show you.
‫And then there are also methods so you can find out whether it's a leap year.
‫Then you can specify the kind days in month.
‫So how many days are in a specific month and year?
‫Because as you know, February can have either 28 or 29 days, then March has 31 days, April has 30
‫days and so forth.
‫So this can be very useful and there is a method for that.
‫Now let's assume we want to have the day which is or the date of tomorrow.
‫And, and in order to get that, we will need to write a little method here.
‫It's going to be static and it's going to return date time and I'm going to call it get tomorrow.
‫And what it will do is it will simply return date time to day.
‫And now today we can add a day.
‫So you can see we can add seconds, takes years, we can compare it and so forth.
‫And the one that I want is I want to add days.
‫As you can see under AD there are multiple different solutions here or options and I'm going to use
‫add days and say one.
‫So I'm just going to add one day to tomorrow and I'm going to return that.
‫So now we can go ahead and use that method in order to apply the day of tomorrow or the date of tomorrow.
‫So I'm going to create a new date time object and I'm going to call it tomorrow, and that will be my
‫tomorrow, which I get by using the get tomorrow method.
‫So there we are.
‫Now our date time tomorrow can be used in order to be displayed.
‫So let's just display tomorrow.
‫Tomorrow will be the and then the tomorrow object.
‫Now let's display that again.
‫And we are tomorrow will be the 13th of June 2018.
‫Now for you is a little challenge right onto the screen, which day of the week we have.
‫So it should be pretty simple.
‫I haven't used it yet, but you can simply go ahead and check out the methods and properties of time
‫to get that.
‫So please go ahead and try that.
‫All right.
‫I hope you tried it.
‫So let's go ahead.
‫Write it onto console.
‫Today is and then we use today so date time dot today dot day of week get the day of the week represented
‫by this instance.
‫All right.
‫So let's print that on to the screen.
‫And we are today is Tuesday.
‫Perfect.
‫I hope you could manage to do that.
‫Now, let's assume we want to get the first day of a specific year so we can go ahead and use static
‫again.
‫Date time.
‫So I'm creating a method here and it's going to be get first day of year.
‫And in here we could either use a date time and just show the date for the first day of that year or
‫we can make it very easy and use an integer.
‫So in here I'm just going to enter a year and it will return a date time.
‫So it will return date time with year one and one because the 1st of January is the first day of the
‫year.
‫So with this one, I'm going to get the first day of a year and I can simply say of which year I want
‫to have the first day.
‫And that's pretty neat because now we can go ahead and display the first day of a specific year.
‫So I'm just going to say first day of year, and that will be, let's say, 1999.
‫And we are 1st of January, 1999.
‫You have seen that you can find out day of the week, but you can also find out the days of the the
‫month has, as I also stated.
‫Let's check it out.
‫Let's create a variable called days and we'll be date time dot days in month and let's say February
‫in 2000.
‫How many days did that day have?
‫And now I'm going to write that onto the console.
‫And days in 2000 were so and so.
‫Now I want to go ahead and check it out for other years as well.
‫So now let's check out 2001.
‫So I'm just going to say days, days and month 2001 and it's going to be February 2001 and now 2004.
‫So let's check that out again.
‫And it will be 2004.
‫So let me print it onto the screen.
‫And we are as you can see, 2000 is a leap year.
‫And 2004 as well.
‫So in 2001, 2002 and so forth.
‫February only has 28 days and each time that it's divisible by four, it has 29 days, even though that's
‫not exactly precise.
‫So there are years where it's skipped.
‫So every I think 100 years is skipped and then once every 400 years is skipped and so forth, because
‫the well, the Earth doesn't actually need 365 days in order to fly around or to make a whole circle
‫around the sun.
‫It needs a little more.
‫So it needs roughly a quarter day more, but it's not exactly a quarter day more.
‫It's something like point two, four days on top.
‫That's why it has to be.
‫Well, as you can see, Skip, well, you can't see it here, but it has to be skipped anyways.
‫All right.
‫So now let's check out how we can get the current time, but in a specific.
‫Menor.
‫So let's go ahead and do that.
‫I'm going to create a date time, which I'm going to call now, and that will be date time now.
‫And now I want to display the current minute.
‫So I'm going to write something like Minute is zero.
‫And that will be now dot minute.
‫So there is this property called minute, then there is one that is called hour and also seconds.
‫And let's display that time now and it says minute is six.
‫So it's 2:00 and 6 minutes and that's what you can see, minutes, six.
‫All right.
‫Now, a little challenge for you.
‫This play the time and this structure.
‫So, so many o clock.
‫Then and so many minutes and Z seconds, so something like 5:00 and 21 minutes and 30 seconds, so maybe
‫5:00.
‫So and so many minutes and so many seconds.
‫So please go ahead and display that onto the console.
‫All right.
‫I hope you tried it.
‫And I'm going to say so o clock then.
‫So minutes and
‫seconds
‫and that will be now.
‫Dot our now, dot minute and now dot second.
‫All right, so let's display that or let's run that to see what the current time is.
‫And we are 40 9:00, 8 minutes and 22 seconds.
‫That's the same thing that you have here.
‫So 2:00.
‫8 minutes.
‫22 seconds.
‫All right.
‫Next, we're going to write a little program which is going to tell us how much time is between now
‫and a time that we enter.
‫So and the date that we enter, to be precise.
‫So write a date in this format and it's going to be y y y standing for a year, year, year.
‫Month, month.
‫Day, day.
‫So that's what we're going to display to the user.
‫And then we get it as input, which will be console dot red line and then we check if that worked out.
‫So if we can make a date time out of whatever was entered.
‫So as you can see, date time has a tri pass method which now can go ahead and try to make sense out
‫of the input that the user has entered.
‫And it's going to have an output which will be date time and now I will use that date time.
‫So I'm going to write date time onto the console and I'm going to create a time span and that time span
‫will have the days past.
‫So however many days have passed since the date that was entered or will pass until the day comes that
‫was entered.
‫So what I do now is I use the now variable that we created earlier on.
‫So this now and I'm going to subtract.
‫So there is this method subtract and what it does, it subtracts the specified date and time from the
‫instance.
‫I want to subtract the date time and that's the output that we get.
‫So whatever the user has entered, which in our case will be, we will be taken and that will be well
‫used in order to calculate this days past.
‫And now finally I want to display that.
‫So I'm going to say days passed since and it will be days past dot days so this time span.
‫Also has a days property which we can use in order to get the days component of the time interval represented
‫by the current time span structure.
‫All right.
‫So if it didn't work out, we're just going to say wrong input.
‫All right.
‫Let's try that.
‫Let's run it.
‫Write a date in this format.
‫So let's say I want to know what happens since 1776.
‫Then month will be July zero seven and the day will be oh four.
‫So that's the Independence Day.
‫And now let's see how much time has passed since until you are 88,366 days.
‫So that's a perfect example of a great celebration on the 88,888 day.
‫Isn't that a great idea?
‫If nobody does that, you should pick that up and create a big eight party which will which will be
‫in roughly a year and three months.
‫So that should be something like October or September.
‫2019.
‫And if you watch this afterwards, then you miss the opportunity to create a party which will be on
‫the 88,888 day after the Independence Day.
‫All right.
‫So now a little challenge.
‫I know this video is long, but bear with me.
‫So please go ahead and write a program where somebody can enter his birthday and it will calculate days
‫passed since.
‫And it's not a difficult one.
‫It's pretty simple, actually, because now you've seen how it works.
‫So please go ahead and try that.
‫All right.
‫I hope you did.
‫So the only thing that I'm going to change is I'm actually changing the text right to date in this format.
‫And to write your birth date date.
‫Is it birth date?
‫Probably its birth date and this format.
‫So now it's the same thing, but now it says not days passed since but something like you are this amount
‫of days old.
‫You are so and so days old.
‫Now let's test that and write your birth date in this format.
‫All right.
‫1990 or 88, in my case, May and 31.
‫And I am 10,969 days old.
‫And you can go ahead and share your days on earth with us if you want to, or you can share your plans
‫for the big celebration of the Independence Day, 88,880 days later.
‫All right.
‫So.
‫Yeah.
‫I hope you enjoyed this video and I hope you have some cool ideas for a great party and see you in the
‫next video.