In this lesson, we're going to be looking at JavaScript Dete, which allows us to get back the current
date using the JavaScript date object.
We've got an example here at the Mozilla Developer Network where we create a brand new date object.
And then within that date object, we have an option to set the date and we can return back a specific
date being returned back.
Or what we can do is we can just specify JavaScript date.
So in order to see that in action, we can set up a variable.
We can call it Dete.
And using DEET, we can do new DEET, and now when we output DEET, we see the current DEET and the
time stamp, just as we see here that's available within the demo using DEET.
We can also be more specific so we can set a value.
We can also use a date string and then we can also use this type of format as well, where we've got
the year, the month index and then we've got the days, hours, minutes, seconds and milliseconds.
So that gives us the ability to set the date in a number of different formats.
Using the date object, we can also return back specific hours within a specified date so we can return
back a date or we can use the current date and we can get the hours associated with the current date.
So let's open up our editor and we're going to try out using the date object.
First, let's set up and set our button to be interactive, to have an event listener, so grabbing
that button element, using a document query selector, selecting it by tag, so using button, adding
in an event listener or adding an event listener to the button.
So whenever it gets clicked, we're going to invoke the function called show output.
Let's set up that function.
So so output is the function that we want it to create and then within so output for now we're going
to console, log out, refresh.
So our button now should be clickable.
We've got works being output there.
Now let's bring in the date object.
So setting up our date under const.
Using new Dete objects are setting that in JavaScript.
And we want to get the current hours of the date right now.
So we can console log out.
And using that brand new date object that we just created, we can use a method called get date, get
ours, get full year so we can return back any one of those objects that are available within the date
object.
Let's refresh Klick message, and now we've got get ours is being returned back, so this is actually
a function.
So don't forget to add in the curly brackets.
Try that one more time and you can see that it returns back the current hours within a 24 hour clock
of the current time.
So it's five p.m., which is seventeen hundred hours.
So go ahead and try this out for yourself.
Set up your HTML, add in a button, make that button clickable with an event listener, and then once
the button is clicked, create a brand new date object and get the current hours that are available
within that date object.
Try it out for yourself.
And coming up, the next lesson.
We're going to continue to build out this project, creating a welcome message depending on what the
time of day it is.
So customized welcome message, depending on the time of day that the user clicks the message button.