1 00:00:01,440 --> 00:00:04,630 Welcome back to Learn to Code and JavaScript in this lecture. 2 00:00:04,650 --> 00:00:06,000 We're going to start talking about dates. 3 00:00:06,990 --> 00:00:13,110 First thing I want to say about dates before we get into too far is that most people don't use the JavaScript 4 00:00:13,110 --> 00:00:13,590 dates. 5 00:00:13,920 --> 00:00:14,700 For the most part. 6 00:00:15,060 --> 00:00:21,840 They'll generally use a library such as Moment Jass, which provides a lot more solid date and time 7 00:00:21,840 --> 00:00:22,710 manipulation. 8 00:00:23,490 --> 00:00:28,770 But we'll take a look here and we will explain what the JavaScript dates are. 9 00:00:29,790 --> 00:00:39,720 So JavaScript data is stored as a number and it's milliseconds since January 1st, 1970 in UTC, which 10 00:00:39,720 --> 00:00:42,840 is the universal time coordinated or Greenwich Mean Time. 11 00:00:43,900 --> 00:00:47,950 So it's a number of milliseconds and before that, time is a negative number. 12 00:00:49,230 --> 00:00:52,590 So, again, most people use the moment, such as library. 13 00:00:52,680 --> 00:00:54,200 So what are the reasons for this? 14 00:00:54,990 --> 00:01:01,390 So in my experience, you can end up with dates that are numbers or objects or strings and with moments. 15 00:01:01,390 --> 00:01:05,460 Yes, it's just nice to have them be a moment object. 16 00:01:07,730 --> 00:01:09,290 So there's two common ways to create a date. 17 00:01:10,250 --> 00:01:16,370 One is to use the new date, which is a constructor, which will talk about more later. 18 00:01:16,880 --> 00:01:23,510 But the new date, you can just specify a string or other formats such as year, month, day, are minutes, 19 00:01:23,510 --> 00:01:24,690 seconds, milliseconds. 20 00:01:25,130 --> 00:01:26,390 You don't have to specify all those. 21 00:01:26,390 --> 00:01:29,210 You just say 20, 21, five, 12. 22 00:01:30,290 --> 00:01:31,490 And that creates a new date. 23 00:01:31,490 --> 00:01:32,540 Both those create a new date. 24 00:01:33,320 --> 00:01:35,120 Now, there's one issue. 25 00:01:35,210 --> 00:01:42,470 There's another issue why people don't like the JavaScript date, which is that the five is not May. 26 00:01:43,410 --> 00:01:50,070 It's June because the JavaScript months start with zero, so January is zero, so it's another thing 27 00:01:50,070 --> 00:01:51,050 called data. 28 00:01:51,090 --> 00:01:53,030 Now, it doesn't really create a date. 29 00:01:53,040 --> 00:01:56,740 It just returns the number of milliseconds since January 1st, 1970. 30 00:01:57,060 --> 00:02:01,650 And so all these are little reasons why people don't like the JavaScript date very much. 31 00:02:01,930 --> 00:02:05,790 So once you have a date, their instance methods, kind of like with strings. 32 00:02:07,530 --> 00:02:09,020 So here are some selected methods. 33 00:02:10,630 --> 00:02:16,990 So when you have a date such as my date, you say get a date, which gets the day of the month, one 34 00:02:16,990 --> 00:02:17,740 three 31. 35 00:02:18,740 --> 00:02:21,380 You say get full year, which gets the four digit year. 36 00:02:22,530 --> 00:02:28,450 And there's a bunch of other guests, as you can see here, get ours, 033, get milliseconds, zero 37 00:02:28,500 --> 00:02:36,210 nine nine nine minutes, get month, you get month is zero to 11, which is kind of confusing. 38 00:02:36,570 --> 00:02:40,500 Get second zero to fifty nine UTC hours. 39 00:02:41,340 --> 00:02:43,910 So get the hours and the UTC time zone. 40 00:02:44,190 --> 00:02:49,560 Let's say it's five o'clock in the Eastern Time zone, it might be ten o'clock at UTC. 41 00:02:50,040 --> 00:02:52,260 And then there's a bunch of set methods as well. 42 00:02:52,260 --> 00:02:55,110 Set month, set minute and so on. 43 00:02:55,830 --> 00:02:58,440 So let's look at some date examples in TVs code.