Last Updated: February 25, 2016
·
2.593K
· jamesvandyke

Use moment.js to handle dates and times in JavaScript

Need to do mathy stuff on time? Convert time zines, parse, add, subtract, convert to fuzzy time (e.g., a moment ago, an hour ago)? Need it to work on your Arabic language site too?

Just use moment.js

http://momentjs.com/

Description: A 5.5kb javascript date library for parsing, validating, manipulating, and formatting dates.

2 Responses
Add your response

Is it possible to get current date using today relative keyword? Something like:
var date = moment('today');

???

over 1 year ago ·

Not using a keyword, but you can by simply calling the moment() function itself, like so:

var now = moment()

For the details about parsing, see http://momentjs.com/docs/#/parsing/now/

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside