How to print date with underscore.js -
how print dates using underscore.js? surprised there apparently way unlike ejs
here do
<%= message.created_at.getfullyear() %>-<%= message.created_at.getmonth() + 1 %>-<%= message.created_at.getdate() %>
underscore's templates (intentionally) simple , minimal there aren't built in formatting utilities. however, can put whatever javascript expressions want inside <%= ... %> can add own formatting utilities. in javascript:
window.fmt = { iso_date: function(d) { // favorite iso 8601 date formatter goes here, // quick hack (which won't work in older ies) // demonstration purposes. return d.toisostring().replace(/t.*$/, ''); }, // other formatting functions need go here... }; and call fmt.iso_date in template thusly:
<%= fmt.iso_date(message.created_at) %>
Comments
Post a Comment