In this video, we are going to talk about dates in JavaScript.
It's very important aspect in Web development, especially when your websites or Web applications have
the relationship with the users.
I mean, that sometimes you may need to get out of the user registration or you may need to check the
time of the payment and many others in all of these cases, you need to know how to deal with dates.
All right, in order to work with the dates, you have to create an instance of the date object, you
can then specify the time and date that you wanted to.
The syntax is the same as it's for creating any object with a constructor notation.
Let's create variable and call it date and assigned to it date object.
By default, when you create a date object, it will hold today's date and the current time.
So this log in, cancel the variable date.
That revolt and let's see what we have here.
So the first is the day of the week, today we have Wednesday, then it's followed by the date.
Today is the 24th of January, 2018.
Then we have the current time, which is followed by the time zone.
When you use that object without setting a specific date of time, JavaScript engine always gives you
a current date and time.
So if you reload the page again, the time will be updated.
If you look at the seconds, you will notice that it's changing on every refresh.
OK, you need to note that the current date and time is determined by the computers clock, if the user
is in a different time zone than you there, they must start earlier or later than yours.
Also, if the internal clock on their computer has the wrong date or time, the date object could reflect
this by holding the wrong date if we change the time zone from computer settings.
Let's set something else here.
Then it will be updated accordingly.
You can make a list of the different states at the time.
There are several formats and ways of doing that.
I'm going to show you one of them, which is a new date string format.
You need to write inside the parentheses, for example, Jan.
20.
Then the year 2020.
And then the time, for example, 10, 14.
Reload and you see that current date and time is changed is the fixed time, because if we refresh again,
it won't be changed.
All right, that object has its built-In methods in JavaScript, if you take a look on the screen,
you will see commonly used dates get methods which lets you to get a part of the data separately.
If you use, for example, getData method, you will get the day of the month as a number from one to
thirty one.
As for the get method, it gives you the weak day as a number from zero to six, this range indicates
the index numbers of the weekdays.
You know that there are seven days in a week.
Therefore, you have index numbers from zero to six.
You can use this index numbers to get the actual weekday names.
As usual, in the first day of the week, has the index number zero, which is Sunday, Monday has one
and so on.
In the same way he works to get mathematics, which is also based on index numbers, we have 12 months
and therefore we have index numbers from zero to 11.
You see here that there are other methods as well, like a full year, get hours, get milliseconds,
get minutes and get seconds.
OK, there is another group of date object methods, and it's called Set Dates Methods.
Set methods are used for setting a part of date so you can set the day of the month.
You can also change current year.
We can set month our minutes, seconds and milliseconds.
All right.
Let's see some examples regarding date methods.
Get rid of these dates, string and use current date reload.
So here we have current date in order to get the part of a date, for example, here we need to use
get full year method.
So create variable year and assign to it.
I thought get full year.
That luggage in Castle.
Reload and you see that we got current year from the date separately in the same way you can get other
parts from date object, for example, let's get map and use here, get mathematic, create variable
math and assigned to each state that gets math.
Then luggage in council as well.
Reload we have now January, which is the first month of the year because of that, the index numbers
of the MASSATA, the based, we got the index number zero.
OK, let's use the set methods which are used for setting the parts of the dates and change.
For example, the current year and month by date dot set a full year and indicate your 1990.
They're set the month, right date, that set month.
And right here, 11.
So you say that the current year is changed from 2018 into 1990 and in the same way January is changed
into December.
All right, there is one thing to note, if you create a variable and assign to it set method.
Right, for example, variable X and then log it in console.
Then you will get a large number.
Let me explain what is that?
This number specifies the number of milliseconds since January the 1st of 1970, so if you count milliseconds
from January 1st, 1970, you will get approximately the same number because it's changing on average
refresh.
It's not very important issue at this point, and I'm not going to waste time on that.
Working with date objects is a very simple you can test other guts and set muscles on your own.
All right, let's move on to the next video in which we are going to build a little digital clock project,
so let's go ahead.