- Let's work on improving the way our
dates look in this application.
And you can see that they're right now appearing
in military format so this should be,
3:50pm and we can control the way the dates look
with a fantastic library called Moment.js
which you can see at this URL.
It's pretty easy to use so,
let's go ahead and take advantage of what it does.
And to do that we're going to need to import our
library which we've already installed.
Let's import Moment from the Moment library.
And once we do that then we can do something with it.
And what I want to do is create a method so we're
going to need to add another element here,
so I'm going to create a list of methods
it's going to have only one right now.
So methods are sort of like functions and Vue.js,
you can call them from within your templates,
and they'll execute and can return
or transform something within your application.
So here we're going to create something
called formattedDate
and this is going to be
a function that's going to receive a date.
And here we'll return
using the Moment library,
a date using the date that we get passed along,
and then we'll use Moment's format function
to modify the format to something a little
more easier to read.
So month, date, year.
And then hour,
minute,
and then an a.m. or a p.m.
And you can read the documentation to see
all of the different strings available.
And there's clearly a lot of other things that
you can do with Moment,
but it just makes it super easy to format dates.
So let's go ahead now
and come up here to where we output the date,
and instead of outputting something from the item,
we're going to use our method,
and pass along the appointment date.
So let's go ahead and save that.
And you should see this appear in a different format.
There are so many libraries in JAVA script that
are super useful and easy to take advantage
in our applications.
So Moment just happens to be one of them.
I really love it because it makes things
like formatting dates which I think is
a little weak in JAVA script,
just a lot easier to use.