Created
May 6, 2012 01:17
-
-
Save distracteddev/2606814 to your computer and use it in GitHub Desktop.
Handlebars Date Helper that doesn't require an array of Months and leverages Date()'s native Localization
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
Ember.Handlebars.registerHelper('date', function(path, options) { | |
date = options.contexts[0].get(path); | |
dateArray = date.toLocaleDateString().split(', '); | |
day = date.getDate() + '. '; | |
// Gets the name of the month form the locaized date string | |
// (A Nice trick to avoid using your own localized date-month maps) | |
month = dateArray.splice(1)[0].split(' ')[0] + ' '; | |
year = 1900 + date.getYear(); | |
return month + day + year; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment