Let's walk through some quick examples. Before we get started, some quick defaults:
- I've created a new SharePoint 2013 site collection using the team site template.
- I've uploaded several documents to the OOB Documents library that I'm provided with.
- I've updated the documents library web part on the home page to show the Created and Modified dates. We're going to work with those.
Let's see what we can do with Moment.js. First things first, we'll need to get the js file added to the page. In order to do that, you'll want to add a script editor to the home page, and add the following:
Now, if you've successfully loaded moment, when you open your console window, you should be able to type moment() and get back an object. Or, you could call moment.format() and see a date string returned.
Very cool, so now how do we use this against our Documents web part on the home page. A couple things to note:
- If you plan to use momentjs throughout your app, load it in the master page. You can decide whether or not you'd like to download a local copy and provision it somewhere or access it via a cdn. Your call.
var dates = document.getElementsByClassName("ms-vb2");
for(var i = 0; i < dates.length; i++)