Created
April 21, 2015 16:57
-
-
Save jeffgabhart/8adf03c756137c818658 to your computer and use it in GitHub Desktop.
Moment JQuery
This file contains hidden or 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
$('.moment-fmt').each(function() { | |
var format = $(this).data('moment-fmt') || ''; | |
var date = $(this).data('moment') || ''; | |
if (date.length) { | |
date = moment.utc(date).local(); | |
if (format.length) { | |
$(this).text(date.format(format)); | |
} else { | |
$(this).text(date); | |
} | |
} | |
}); | |
$('.moment-diff-days').each(function() { | |
var date = $(this).data('moment') || ''; | |
if (date.length) { | |
date = moment.utc(date); | |
var label = ' days'; | |
var now = moment.utc(); | |
var diff = date.diff(now, 'days'); | |
if (diff == 1) { | |
label = ' day'; | |
} | |
$(this).text(diff + label); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment