WEBVTT

00:01.210 --> 00:04.360
In this video, we are going to talk about dates in JavaScript.

00:04.570 --> 00:10.120
It's very important aspect in Web development, especially when your websites or Web applications have

00:10.120 --> 00:11.700
the relationship with the users.

00:12.400 --> 00:18.160
I mean, that sometimes you may need to get out of the user registration or you may need to check the

00:18.160 --> 00:24.310
time of the payment and many others in all of these cases, you need to know how to deal with dates.

00:25.310 --> 00:31.190
All right, in order to work with the dates, you have to create an instance of the date object, you

00:31.190 --> 00:34.610
can then specify the time and date that you wanted to.

00:35.540 --> 00:40.570
The syntax is the same as it's for creating any object with a constructor notation.

00:41.180 --> 00:47.090
Let's create variable and call it date and assigned to it date object.

00:49.220 --> 00:54.670
By default, when you create a date object, it will hold today's date and the current time.

00:55.140 --> 00:57.500
So this log in, cancel the variable date.

01:02.090 --> 01:05.490
That revolt and let's see what we have here.

01:05.990 --> 01:12.760
So the first is the day of the week, today we have Wednesday, then it's followed by the date.

01:13.190 --> 01:18.000
Today is the 24th of January, 2018.

01:18.650 --> 01:22.010
Then we have the current time, which is followed by the time zone.

01:23.210 --> 01:28.950
When you use that object without setting a specific date of time, JavaScript engine always gives you

01:28.950 --> 01:30.190
a current date and time.

01:30.920 --> 01:35.180
So if you reload the page again, the time will be updated.

01:35.810 --> 01:39.920
If you look at the seconds, you will notice that it's changing on every refresh.

01:40.990 --> 01:49.150
OK, you need to note that the current date and time is determined by the computers clock, if the user

01:49.150 --> 01:55.240
is in a different time zone than you there, they must start earlier or later than yours.

01:55.960 --> 02:02.530
Also, if the internal clock on their computer has the wrong date or time, the date object could reflect

02:02.530 --> 02:08.560
this by holding the wrong date if we change the time zone from computer settings.

02:10.580 --> 02:12.940
Let's set something else here.

02:15.980 --> 02:18.790
Then it will be updated accordingly.

02:21.060 --> 02:23.650
You can make a list of the different states at the time.

02:24.180 --> 02:26.860
There are several formats and ways of doing that.

02:26.880 --> 02:31.470
I'm going to show you one of them, which is a new date string format.

02:32.220 --> 02:36.810
You need to write inside the parentheses, for example, Jan.

02:38.280 --> 02:38.940
20.

02:40.380 --> 02:43.770
Then the year 2020.

02:45.160 --> 02:48.730
And then the time, for example, 10, 14.

02:51.390 --> 02:58.650
Reload and you see that current date and time is changed is the fixed time, because if we refresh again,

02:58.650 --> 02:59.790
it won't be changed.

03:01.200 --> 03:07.470
All right, that object has its built-In methods in JavaScript, if you take a look on the screen,

03:07.500 --> 03:13.880
you will see commonly used dates get methods which lets you to get a part of the data separately.

03:14.580 --> 03:21.540
If you use, for example, getData method, you will get the day of the month as a number from one to

03:21.540 --> 03:22.320
thirty one.

03:23.660 --> 03:30.560
As for the get method, it gives you the weak day as a number from zero to six, this range indicates

03:30.560 --> 03:32.210
the index numbers of the weekdays.

03:32.780 --> 03:34.790
You know that there are seven days in a week.

03:34.800 --> 03:38.080
Therefore, you have index numbers from zero to six.

03:38.960 --> 03:42.350
You can use this index numbers to get the actual weekday names.

03:43.350 --> 03:49.980
As usual, in the first day of the week, has the index number zero, which is Sunday, Monday has one

03:49.980 --> 03:50.580
and so on.

03:51.600 --> 03:57.950
In the same way he works to get mathematics, which is also based on index numbers, we have 12 months

03:57.960 --> 04:01.050
and therefore we have index numbers from zero to 11.

04:02.510 --> 04:09.440
You see here that there are other methods as well, like a full year, get hours, get milliseconds,

04:09.440 --> 04:11.030
get minutes and get seconds.

04:12.400 --> 04:18.100
OK, there is another group of date object methods, and it's called Set Dates Methods.

04:18.940 --> 04:24.770
Set methods are used for setting a part of date so you can set the day of the month.

04:24.790 --> 04:27.370
You can also change current year.

04:28.270 --> 04:31.930
We can set month our minutes, seconds and milliseconds.

04:33.460 --> 04:33.940
All right.

04:34.360 --> 04:36.790
Let's see some examples regarding date methods.

04:36.790 --> 04:41.370
Get rid of these dates, string and use current date reload.

04:41.890 --> 04:48.220
So here we have current date in order to get the part of a date, for example, here we need to use

04:48.670 --> 04:49.900
get full year method.

04:50.350 --> 04:54.430
So create variable year and assign to it.

04:54.460 --> 04:56.680
I thought get full year.

04:57.770 --> 04:59.090
That luggage in Castle.

05:04.980 --> 05:12.000
Reload and you see that we got current year from the date separately in the same way you can get other

05:12.000 --> 05:19.530
parts from date object, for example, let's get map and use here, get mathematic, create variable

05:19.530 --> 05:23.520
math and assigned to each state that gets math.

05:25.950 --> 05:28.250
Then luggage in council as well.

05:32.400 --> 05:39.290
Reload we have now January, which is the first month of the year because of that, the index numbers

05:39.290 --> 05:42.650
of the MASSATA, the based, we got the index number zero.

05:43.370 --> 05:49.280
OK, let's use the set methods which are used for setting the parts of the dates and change.

05:49.280 --> 06:00.140
For example, the current year and month by date dot set a full year and indicate your 1990.

06:02.140 --> 06:05.560
They're set the month, right date, that set month.

06:07.400 --> 06:09.920
And right here, 11.

06:11.780 --> 06:19.880
So you say that the current year is changed from 2018 into 1990 and in the same way January is changed

06:19.880 --> 06:20.780
into December.

06:22.170 --> 06:28.230
All right, there is one thing to note, if you create a variable and assign to it set method.

06:30.030 --> 06:34.680
Right, for example, variable X and then log it in console.

06:37.980 --> 06:39.930
Then you will get a large number.

06:40.850 --> 06:42.260
Let me explain what is that?

06:42.500 --> 06:52.100
This number specifies the number of milliseconds since January the 1st of 1970, so if you count milliseconds

06:52.100 --> 06:59.570
from January 1st, 1970, you will get approximately the same number because it's changing on average

06:59.570 --> 07:00.050
refresh.

07:00.830 --> 07:04.850
It's not very important issue at this point, and I'm not going to waste time on that.

07:05.660 --> 07:11.960
Working with date objects is a very simple you can test other guts and set muscles on your own.

07:12.890 --> 07:18.910
All right, let's move on to the next video in which we are going to build a little digital clock project,

07:19.430 --> 07:20.330
so let's go ahead.
