When using Meteor's Handlebar bracers, how do you convert the output of {{ timestamp }} from Thu Jul 25 2013 19:33:19 GMT-0400 (Eastern Daylight Time) to Jul 25?
Tried {{ timestamp.toString('yyyy-MM-dd') }} but it gave an error
Use a handlebars helper:
Template.registerHelper("prettifyDate", function(timestamp) {
return new Date(timestamp).toString('yyyy-MM-dd')
});
Then in your html:
{{prettifyDate timestamp}}
If you use moment:
Template.registerHelper("prettifyDate", function(timestamp) {
return moment(new Date(timestamp)).fromNow();
});
This worked for me
Handlebars.registerHelper("prettifyDate", function(timestamp) {
return (new Date(timestamp)).format("yyyy-MM-dd");
});
This works for me.
toString("yyyy-MM-dd") - doesn't convert it.
Template.registerHelper("prettifyDate", function(timestamp) {
var curr_date = timestamp.getDate();
var curr_month = timestamp.getMonth();
curr_month++;
var curr_year = timestamp.getFullYear();
result = curr_date + ". " + curr_month + ". " + curr_year;
return result;
});