-
-
Save umardx/5dee025d05c4ca4761818de4e76769d3 to your computer and use it in GitHub Desktop.
Moment.js examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node: | |
var moment = require('moment'); | |
moment().add('days', 2).fromNow(); | |
// 'in 2 days' | |
moment().subtract('days', 2).fromNow(); | |
// '2 days ago' | |
moment('November 1977').fromNow() | |
// '34 years ago' | |
moment().add('days', 2).calendar(); | |
// 'Monday at 8:30 AM' | |
moment().subtract('days', 2).calendar(); | |
// 'last Thursday at 8:30 AM' | |
moment('1977-08-20 14:29:00 UTC').format('MMM. d, YYYY'); | |
// 'Aug. 5, 1977' | |
moment('1977-08-20 14:29:00 UTC').fromNow(); | |
// 'il y a 35 années' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>in a Moment.js</title> | |
</head> | |
<body> | |
<h1>Moment.js here now: <span id="then" data-date="Sat Mar 24 2012 08:42:14 GMT-0400 (EDT)"></span></h1> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script src="/js/moment.js"></script> | |
<script> | |
$(document).ready(function(){ | |
var then = $('#then'), | |
date = moment(new Date(then.attr('data-date'))), | |
update = function(){ | |
then.html(date.fromNow()); | |
}; | |
update(); | |
setInterval(update, 60000); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment