Created
August 20, 2012 23:17
-
-
Save stephentcannon/3409103 to your computer and use it in GitHub Desktop.
Moment.js handlebars helper
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
// format an ISO date using Moment.js | |
// http://momentjs.com/ | |
// moment syntax example: moment(Date("2011-07-18T15:50:52")).format("MMMM YYYY") | |
// usage: {{dateFormat creation_date format="MMMM YYYY"}} | |
Handlebars.registerHelper('dateFormat', function(context, block) { | |
if (window.moment) { | |
var f = block.hash.format || "MMM DD, YYYY hh:mm:ss A"; | |
return moment(context).format(f); //had to remove Date(context) | |
}else{ | |
return context; // moment plugin not available. return data as is. | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get this error: window is not defined