Created
March 24, 2012 12:53
-
-
Save founddrama/2182389 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> |
I have to make a time difference between server time (Netherlands) and local. I have to check 24 laps time after last modification. How can I convert current client side time to Netherlands time so that I can check difference.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example:
moment('1977-08-20 14:29:00 UTC').format('MMM. d, YYYY');
The 'd' should be 'D' to give Aug, 20, 1977