[MUSIC].
>> Hi there. Christopher Harrison,
Senior Program Manager, Microsoft Cloud and AI.
Let's see how we can work with dates through
demo inside of JavaScript.
Here is my little IDE, of course it's empty.
What I'm going to do is I'm going to say cons on now
equals new date, just like that.
Then, let's just go ahead and do a console log and
then now to go ahead and print that out.
If I go ahead and I say node of my dates dot js,
what you're going to notice is it's going to give us
this standardized time where
it's going to tell us the year, month and day.
Then, it's going to give us the time here and
it's going to be offset from UTC.
So that's why it currently says 23:00 here.
It's actually four o'clock.
If you do some real quick math,
I'm in the Pacific Time Zone,
that would lead you to that 23:00 there.
Now, one thing that's worth noting is the fact that we can always
go in and manipulate the date
or specify a date that we might want.
So I could say something like const win95Launch equals new date.
Then, it's going to show us that we've got
a few different overloads that we can take advantage of here.
I'm going to specify the day as 1995.
I'm going to specify the month as August,
and remember that that's going to be seven and then,
I'm going to specify the day as 24.
Then, let's go ahead and print that out.
Win95Launch, just like that,
and now let's just go ahead and run this.
Now, what you're going to notice is that it gives
me that 1995, eight because again,
August, our counting on months is going to start with
zero and then 24, just like that.
It's going to set the time to midnight.
Again, remember the fact that it's always
going to be based off of UTC.
Now, I am presently UTC minus seven here.
So that's why it's showing you that 7:00 AM,
it's actually going to be midnight.
Now, if you want to play around with the date.
Let's say const, demoDate,
very creative with my names, equals new date.
I can demo date dot,
and then start setting really
any individual component that I might want on this.
I can set the date,
I can set the hours,
I can set the month,
whatever it is that I might want.
If I want to maybe change the month to be January,
again that's going to be zero.
Then, I go ahead and say console.log my demoDate,
and now let's go ahead and just rerun that.
Cool. It's going to be this first one here.
Now, what you're going to notice right there, that 01,
that is going to be the month that I set it to.
Now, it's also worth highlighting the fact that
we can go get individual,
let me just move all of this down here,
there we go, that we can always get individual components as well.
I could maybe do something like this where I say console.log,
such a wonderful toy,
and then I can say maybe day of week,
and then like this use
the cool little string formatting that's available,
and then I could say my demoDate.getDay, let say.
What this is going to give us,
is starting with zero,
it's going to give us the day of the week.
Zero would be Sunday,
one would be Monday,
and then the two here would indicate Tuesday.
Whatever component it is that you might want,
maybe I could say the date.
This would actually be the calendar date,
I could go in and say getDate,
just like that, save,
rerun that, and now what you're going to notice
is that date of 21.
Cool. Now, granted there obviously is a lot
more available to you when it comes to
working with dates inside of JavaScript.
The goal here was to show off some
of the more common core things
that you might want to work with the date,
but if you check out the supporting materials, check out the docs,
you're going to notice there is a lot
more that you can play around
with when it comes to dates inside of JavaScript.
Hopefully that gave you the core,
and then from here, you can continue to build.