Skip to content

Instantly share code, notes, and snippets.

@distracteddev
Created May 6, 2012 01:17
Show Gist options
  • Save distracteddev/2606814 to your computer and use it in GitHub Desktop.
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
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