Skip to content

Instantly share code, notes, and snippets.

@jwaltonmedia
Created May 27, 2013 18:24
Show Gist options
  • Save jwaltonmedia/5658411 to your computer and use it in GitHub Desktop.
Save jwaltonmedia/5658411 to your computer and use it in GitHub Desktop.
Dustjs helper for formatting javascript date strings in templates (server-side).
dust.helpers.formatDate = function(chunk, context, bodies, params) {
var value = dust.helpers.tap(params.value, chunk, context),
timestamp,
month,
date,
year;
timestamp = new Date(value);
month = timestamp.getMonth() + 1;
date = timestamp.getDate();
year = timestamp.getFullYear();
return chunk.write(month + '.' + date + '.' + year);
};
//then to use it: {@formatDate vale="{YOUR JS DATE VALUE}"/}
//how to make helpers? https://github.com/linkedin/dustjs/wiki/Dust-Tutorial#wiki-Writing_a_dust_helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment