-
-
Save founddrama/2182389 to your computer and use it in GitHub Desktop.
// 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' |
<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> |
tks ! =]
How can I pass parameters to moment js ?
var a = moment('2016-06-06T21:03:55');//now
var b = moment('2016-05-06T20:03:55');
console.log(a.diff(b, 'minutes')) // 44700
console.log(a.diff(b, 'hours')) // 745
console.log(a.diff(b, 'days')) // 31
console.log(a.diff(b, 'weeks')) // 4
This works fine .
When when I am trying to do
console.log("from_url "+from_url); //prints: 2016-05-03T10:00:00
var a = moment(from_url);
console.log("a "+a); //prints : 1462294800000 isntead of 2016-05-03T10:00:00
Please help me out. It is kinda urgent.
Thanks.
This example:
moment('1977-08-20 14:29:00 UTC').format('MMM. d, YYYY');
The 'd' should be 'D' to give Aug, 20, 1977
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.
mark