Change createdAt format


#1

I want to display {{name}} - {{createdAt}}, but i get the format from database pop - Thu Aug 25 2016 20:42:00 GMT+0300 (GTB Summer Time)

How do i change the format to something more friendly like yyyy-MM-dd

Collection:

Cvs = new Mongo.Collection('cvs');
...
    createdAt: {
        type: Date,

I tried like in this example

Template.registerHelper("prettifyDate", function(timestamp){
    return new Date(timestamp).toString('yyyy-MM-dd')
})

{{prettifyDate createdAt}}

, but nothing is changed.


Display Date Format "DD-MM-YYYY"
#2

My strategy:

import { moment } from 'meteor/momentjs:moment';

Template.registerHelper('formatDate', function(date, format) {
  // Use moment.js formatting to return a date we like (http://momentjs.com/)
  // Example: {{formatDate createdAt 'MM/DD/YYYY'}}

  return moment(new Date(date)).format(format);
});


#3

Thanks @vigorwebsolutions !