1 00:00:00,830 --> 00:00:11,020 HARLOW In this lesson you are going to learn how to get the date and the time. 2 00:00:11,200 --> 00:00:14,410 Go ahead and download this new File 0 7. 3 00:00:14,440 --> 00:00:21,890 Getting the time is it from the resource section and put it in your face in projects hold it and then 4 00:00:21,980 --> 00:00:22,430 ICP 5 00:00:29,140 --> 00:00:35,280 now you can vary the zip file and open the new folder 6 00:00:38,520 --> 00:00:42,090 and open the same file call getting a time 7 00:00:45,110 --> 00:00:49,580 yes run it and see what he does on run compile 8 00:00:52,650 --> 00:01:00,060 and you get a new ECF at so that's copy these Pfaff correctly copy 9 00:01:02,790 --> 00:01:15,080 and entered a new dietary type city space and paste upon the idea to check in you find then find a name 10 00:01:15,080 --> 00:01:31,390 of the FA and presenter to execute and you get the year dash the month which is April dash the day the 11 00:01:31,480 --> 00:01:40,140 date which is eight year time which is for 0 4 and the second which is 5. 12 00:01:41,450 --> 00:01:51,960 Press Hiroki and run again and now you see twenty nine seconds I'm a rookie again and now there is a 13 00:01:51,970 --> 00:01:52,970 second. 14 00:01:53,020 --> 00:01:55,680 So the format is here month. 15 00:01:56,780 --> 00:02:02,740 Day our many seconds. 16 00:02:03,150 --> 00:02:04,980 So let's see how the program works 17 00:02:19,900 --> 00:02:29,030 so this program is where you learn how to get in debt in time using two Windows API functions get local 18 00:02:29,030 --> 00:02:32,170 time or get system time. 19 00:02:32,410 --> 00:02:36,620 Be sure the same produce the same output. 20 00:02:36,830 --> 00:02:43,950 Over here we create a string of the string which has this format specify it. 21 00:02:44,630 --> 00:02:46,890 We have a presentation. 22 00:02:47,930 --> 00:02:59,930 The the the for the first four numbers which is 2 0 2 0 dash then dash is here followed by them month 23 00:03:00,860 --> 00:03:11,920 dash again followed by the date dash again followed by the Hauer and then colon colon here. 24 00:03:12,070 --> 00:03:21,420 As you can see colon followed by the mini other colon here followed by the seconds. 25 00:03:21,590 --> 00:03:22,790 So this is the second. 26 00:03:23,150 --> 00:03:38,770 So we get here month they our 90 seconds and then under the V.A. cessation we declare and use data data 27 00:03:38,780 --> 00:03:41,720 type call system. 28 00:03:41,910 --> 00:03:46,240 It is this structure so a structure is a complex deal. 29 00:03:47,550 --> 00:03:55,590 And the data type is called system time and the variable created out of it is called This Time. 30 00:03:56,430 --> 00:04:02,600 So this is a very one in and this is a name on the data structure. 31 00:04:03,010 --> 00:04:14,710 And over here we call the windows api call gate system time and push one parameter. 32 00:04:15,370 --> 00:04:21,160 Let's check out the amnesty and see how this is gate system time 33 00:04:23,930 --> 00:04:32,660 give system time a sense of one parameter the system time data data structure by returns nothing else 34 00:04:32,720 --> 00:04:34,110 you can see here. 35 00:04:34,130 --> 00:04:35,480 System tabular structure 36 00:04:39,380 --> 00:04:40,140 you can take a look. 37 00:04:40,230 --> 00:04:46,200 Hey Santangelo structure and these are the numbers all of these get us richer 38 00:04:49,310 --> 00:04:53,400 simply from here you know it only accepts one time it's a. 39 00:04:54,080 --> 00:05:03,350 So here this is a barometer referring to this is in time and there's also another call get local time 40 00:05:04,120 --> 00:05:09,200 issue we look at it later which also accepts one barometer. 41 00:05:09,200 --> 00:05:13,130 So now we want to call this function 0 here. 42 00:05:13,610 --> 00:05:17,300 And once you kind of function he will return the result. 43 00:05:17,450 --> 00:05:21,970 Inside the perimeter itself. 44 00:05:22,010 --> 00:05:27,720 So once you get the result inside the perimeter itself you can get a straight. 45 00:05:27,860 --> 00:05:39,320 All of these numbers here man they'll the hour minute second in milliseconds. 46 00:05:39,350 --> 00:05:41,260 And this is very do it. 47 00:05:41,300 --> 00:05:51,450 We extract the year and save it in the yaks register the essay the year by calling the system time which 48 00:05:51,590 --> 00:06:01,600 you get back from here and put a dot you put a dot here to access the members of the get out structure 49 00:06:03,410 --> 00:06:06,130 so w year refers to the year. 50 00:06:06,380 --> 00:06:10,870 Nevermind refers to a month that video refers to the day here. 51 00:06:11,930 --> 00:06:20,290 Every hour he refers to the hour every minute refers to me and every seconds before the seconds. 52 00:06:20,630 --> 00:06:23,090 So he asked me a copy. 53 00:06:23,240 --> 00:06:24,710 Oh this year. 54 00:06:24,710 --> 00:06:28,760 Monday how many seconds into their respective registers. 55 00:06:28,760 --> 00:06:29,810 He actually. 56 00:06:29,890 --> 00:06:30,400 Easy. 57 00:06:30,690 --> 00:06:31,100 Yes. 58 00:06:31,150 --> 00:06:33,160 Yes I am. 59 00:06:34,110 --> 00:06:42,730 Now here you notice that uh we use a new more instruction called Move 0 x. 60 00:06:42,980 --> 00:06:44,330 Why do we need to. 61 00:06:44,480 --> 00:06:46,860 What's the meaning of this 0 x. 62 00:06:46,860 --> 00:06:52,500 The race is to fill the bits with zeros. 63 00:06:52,550 --> 00:06:54,160 Why do we need to do that. 64 00:06:54,470 --> 00:06:55,310 Let's take a look. 65 00:06:56,750 --> 00:06:59,620 Now we type the. 66 00:07:01,190 --> 00:07:08,770 And now we know that E X register consists of 4 bytes one. 67 00:07:08,800 --> 00:07:20,780 This is one by to base three bytes for bytes also known as deal with but the system time since time 68 00:07:21,620 --> 00:07:29,680 w year w among the gloomy days every hour double meaning and b seconds are all words. 69 00:07:30,450 --> 00:07:34,630 OK so let me put a knucklehead remark here. 70 00:07:34,670 --> 00:07:41,200 D e d d word which is for whites for whites 71 00:07:44,480 --> 00:07:48,410 and since time is a word 72 00:07:51,320 --> 00:07:58,710 which is two bytes two bytes. 73 00:07:59,120 --> 00:08:04,940 So when we copy the uh oh what a word. 74 00:08:04,940 --> 00:08:10,850 This is a word sorry we need to put the prefix and we copy a word which is to base into a for widespread 75 00:08:10,850 --> 00:08:11,290 use. 76 00:08:11,930 --> 00:08:15,390 We need to zero up the remaining bytes. 77 00:08:15,620 --> 00:08:21,650 So after you copy this you will get these two bytes being populated. 78 00:08:21,650 --> 00:08:26,230 That means you will get something like this. 79 00:08:26,840 --> 00:08:31,340 The lower two bytes will be say the year 2 2 0. 80 00:08:32,420 --> 00:08:40,960 But they are higher for bytes really 2 0 8 0 next 0. 81 00:08:40,970 --> 00:08:43,750 Now we don't know what the original value of EIC is. 82 00:08:43,750 --> 00:08:45,580 It could be something like this 83 00:08:51,580 --> 00:08:56,890 it could be something like this some random value from the previous use of the register. 84 00:08:57,550 --> 00:09:06,670 So when we when we copy this word into this what we actually will get is something like this 85 00:09:12,570 --> 00:09:14,390 or 2. 86 00:09:15,340 --> 00:09:16,400 Correct. 87 00:09:16,400 --> 00:09:22,200 Because we are only copying two bytes so we only copy two bytes into the lower two bytes here and we 88 00:09:22,210 --> 00:09:23,190 get this. 89 00:09:23,390 --> 00:09:25,850 But what about the other higher two bytes. 90 00:09:26,870 --> 00:09:28,450 So this would be wrong clearly. 91 00:09:28,490 --> 00:09:41,410 So that is why we need to use a more physics function move ze X move the X to copy these two guys and 92 00:09:41,410 --> 00:09:48,920 put it in the lower two bites of the e register and at the same time he was 0 0 the rest. 93 00:09:48,920 --> 00:09:51,230 That means what we get is 94 00:09:56,870 --> 00:09:57,880 like this. 95 00:09:57,920 --> 00:10:05,070 So there is a meaning on the Z ze X just means to zero on your higher base. 96 00:10:05,120 --> 00:10:05,410 Okay. 97 00:10:05,420 --> 00:10:08,800 So not I hope you understand what it means. 98 00:10:08,940 --> 00:10:10,220 So there is some meaning out there. 99 00:10:10,250 --> 00:10:14,030 So we zero up in the higher form by had a higher to base. 100 00:10:14,060 --> 00:10:22,010 So after we have copied how these uh values into the respective registers we are now ready to print. 101 00:10:22,520 --> 00:10:29,490 So the next uh part of the code is where we push all this into the stack as barometer for the print 102 00:10:29,600 --> 00:10:30,890 function. 103 00:10:30,890 --> 00:10:34,210 So reposting in reverse order tell you one. 104 00:10:34,640 --> 00:10:41,070 So we V1 EDF media seconds TV the last uh part of the string. 105 00:10:41,180 --> 00:10:46,700 So we push this first then we push ECI EDF. 106 00:10:46,700 --> 00:10:49,430 Easy s e s e x. 107 00:10:49,520 --> 00:10:56,390 And finally we push the gate format they get string which is referring to this. 108 00:10:56,390 --> 00:11:06,190 So when you comprehend we never replace the first form a specified D B X then you print a dash. 109 00:11:06,190 --> 00:11:12,730 You've a second from a Swiss he PBX been a dash in the top one with his yes. 110 00:11:13,160 --> 00:11:15,270 Been a day in the forefront. 111 00:11:15,620 --> 00:11:18,110 He has been a colon. 112 00:11:18,110 --> 00:11:28,170 Being a fifth y yes I colon and being the last Monday he I and that would give us to this three. 113 00:11:28,330 --> 00:11:29,710 So this is how it works. 114 00:11:29,860 --> 00:11:39,160 And finally we have to clean this stack because there are seven pushers so we need to four times seven. 115 00:11:39,280 --> 00:11:45,850 And so after that you will go to the exit process and the program will end and notice here you have 116 00:11:45,850 --> 00:11:53,360 to add this extra two lines because we are using these two API functions. 117 00:11:53,570 --> 00:11:53,830 Right. 118 00:11:53,830 --> 00:12:03,200 So here you are using get system time guess system time which we import here by now. 119 00:12:03,310 --> 00:12:05,950 We are also going to do get local time. 120 00:12:05,950 --> 00:12:11,760 So now I'm going to substitute this code get local time. 121 00:12:11,810 --> 00:12:14,440 Me and commands and command is. 122 00:12:15,040 --> 00:12:22,810 And I'm going to compile one more time and then we are going to run the same program. 123 00:12:22,810 --> 00:12:28,140 So there is some difference in the time here because the local time is based on a country time zone 124 00:12:28,960 --> 00:12:29,350 system. 125 00:12:29,350 --> 00:12:32,760 Time is getting a time off your system. 126 00:12:32,920 --> 00:12:35,020 So that's why the time is slightly different. 127 00:12:35,620 --> 00:12:39,820 So we can use either one to get the date and the time. 128 00:12:40,600 --> 00:12:43,650 So try to experiment with this. 129 00:12:43,930 --> 00:12:52,960 Why not try to do an exercise on your own to write a program that can ask the user to enter name and 130 00:12:52,980 --> 00:13:01,550 enter from the name you get the first four characters and then combine it with the date in it to create 131 00:13:01,550 --> 00:13:02,670 a new String. 132 00:13:02,750 --> 00:13:04,580 See if you can do on your own. 133 00:13:04,670 --> 00:13:06,390 We can try on your own as an exercise. 134 00:13:06,830 --> 00:13:09,050 So that's all for this lesson. 135 00:13:09,110 --> 00:13:10,390 Thank you for watching.