HARLOW In this lesson you are going to learn how to get the date and the time.
Go ahead and download this new File 0 7.
Getting the time is it from the resource section and put it in your face in projects hold it and then
ICP
now you can vary the zip file and open the new folder
and open the same file call getting a time
yes run it and see what he does on run compile
and you get a new ECF at so that's copy these Pfaff correctly copy
and entered a new dietary type city space and paste upon the idea to check in you find then find a name
of the FA and presenter to execute and you get the year dash the month which is April dash the day the
date which is eight year time which is for 0 4 and the second which is 5.
Press Hiroki and run again and now you see twenty nine seconds I'm a rookie again and now there is a
second.
So the format is here month.
Day our many seconds.
So let's see how the program works
so this program is where you learn how to get in debt in time using two Windows API functions get local
time or get system time.
Be sure the same produce the same output.
Over here we create a string of the string which has this format specify it.
We have a presentation.
The the the for the first four numbers which is 2 0 2 0 dash then dash is here followed by them month
dash again followed by the date dash again followed by the Hauer and then colon colon here.
As you can see colon followed by the mini other colon here followed by the seconds.
So this is the second.
So we get here month they our 90 seconds and then under the V.A. cessation we declare and use data data
type call system.
It is this structure so a structure is a complex deal.
And the data type is called system time and the variable created out of it is called This Time.
So this is a very one in and this is a name on the data structure.
And over here we call the windows api call gate system time and push one parameter.
Let's check out the amnesty and see how this is gate system time
give system time a sense of one parameter the system time data data structure by returns nothing else
you can see here.
System tabular structure
you can take a look.
Hey Santangelo structure and these are the numbers all of these get us richer
simply from here you know it only accepts one time it's a.
So here this is a barometer referring to this is in time and there's also another call get local time
issue we look at it later which also accepts one barometer.
So now we want to call this function 0 here.
And once you kind of function he will return the result.
Inside the perimeter itself.
So once you get the result inside the perimeter itself you can get a straight.
All of these numbers here man they'll the hour minute second in milliseconds.
And this is very do it.
We extract the year and save it in the yaks register the essay the year by calling the system time which
you get back from here and put a dot you put a dot here to access the members of the get out structure
so w year refers to the year.
Nevermind refers to a month that video refers to the day here.
Every hour he refers to the hour every minute refers to me and every seconds before the seconds.
So he asked me a copy.
Oh this year.
Monday how many seconds into their respective registers.
He actually.
Easy.
Yes.
Yes I am.
Now here you notice that uh we use a new more instruction called Move 0 x.
Why do we need to.
What's the meaning of this 0 x.
The race is to fill the bits with zeros.
Why do we need to do that.
Let's take a look.
Now we type the.
And now we know that E X register consists of 4 bytes one.
This is one by to base three bytes for bytes also known as deal with but the system time since time
w year w among the gloomy days every hour double meaning and b seconds are all words.
OK so let me put a knucklehead remark here.
D e d d word which is for whites for whites
and since time is a word
which is two bytes two bytes.
So when we copy the uh oh what a word.
This is a word sorry we need to put the prefix and we copy a word which is to base into a for widespread
use.
We need to zero up the remaining bytes.
So after you copy this you will get these two bytes being populated.
That means you will get something like this.
The lower two bytes will be say the year 2 2 0.
But they are higher for bytes really 2 0 8 0 next 0.
Now we don't know what the original value of EIC is.
It could be something like this
it could be something like this some random value from the previous use of the register.
So when we when we copy this word into this what we actually will get is something like this
or 2.
Correct.
Because we are only copying two bytes so we only copy two bytes into the lower two bytes here and we
get this.
But what about the other higher two bytes.
So this would be wrong clearly.
So that is why we need to use a more physics function move ze X move the X to copy these two guys and
put it in the lower two bites of the e register and at the same time he was 0 0 the rest.
That means what we get is
like this.
So there is a meaning on the Z ze X just means to zero on your higher base.
Okay.
So not I hope you understand what it means.
So there is some meaning out there.
So we zero up in the higher form by had a higher to base.
So after we have copied how these uh values into the respective registers we are now ready to print.
So the next uh part of the code is where we push all this into the stack as barometer for the print
function.
So reposting in reverse order tell you one.
So we V1 EDF media seconds TV the last uh part of the string.
So we push this first then we push ECI EDF.
Easy s e s e x.
And finally we push the gate format they get string which is referring to this.
So when you comprehend we never replace the first form a specified D B X then you print a dash.
You've a second from a Swiss he PBX been a dash in the top one with his yes.
Been a day in the forefront.
He has been a colon.
Being a fifth y yes I colon and being the last Monday he I and that would give us to this three.
So this is how it works.
And finally we have to clean this stack because there are seven pushers so we need to four times seven.
And so after that you will go to the exit process and the program will end and notice here you have
to add this extra two lines because we are using these two API functions.
Right.
So here you are using get system time guess system time which we import here by now.
We are also going to do get local time.
So now I'm going to substitute this code get local time.
Me and commands and command is.
And I'm going to compile one more time and then we are going to run the same program.
So there is some difference in the time here because the local time is based on a country time zone
system.
Time is getting a time off your system.
So that's why the time is slightly different.
So we can use either one to get the date and the time.
So try to experiment with this.
Why not try to do an exercise on your own to write a program that can ask the user to enter name and
enter from the name you get the first four characters and then combine it with the date in it to create
a new String.
See if you can do on your own.
We can try on your own as an exercise.
So that's all for this lesson.
Thank you for watching.