0

my date got the format like this... Wed Sep 09 2015 11:43:40 GMT+0200 (CEST)

This is the way I insert the data into the mongodb...

Tasks.insert({
        text: text,
        gerätename: gerätenummer,
        createdAt: new Date() // current time
 });

But now I want only a the date format like day/month/year and time in the frontend.

What I have to change in the following code that it will work.

Template.body.helpers({
    tasks: function () {
      // Show newest tasks at the top
      return Tasks.find({}, {sort: {createdAt: -1}});
    }
 });

<template name="task">
    <li class="{{#if checked}}checked{{/if}}">
        <button class="delete">&times;</button>
        <input type="checkbox" checked="{{checked}}" class="toggle-checked" />
        <span class="text">{{text}}</span>
        <span class="text">{{gerätename}}</span>
        <span clas="text">{{createdAt}}</span>
    </li>
</template>

Thank you!

peter411
  • 19
  • 3
  • this is not going to help me regarding to my problem – peter411 Sep 10 '15 at 13:18
  • You need to create a template helper to format the date. Go `Template.task.helpers({formatDate: function (date) { /* insert date formatting code from the linked question */ }})` and then replace `{{createdAt}}` with `{{formatDate createdAt}}`. I'd post this as an answer but the question was (IMO incorrectly) closed. – user3374348 Sep 10 '15 at 14:56
  • 1
    I agree this is a duplicate, but a meteor-specific answer can be found [here](https://stackoverflow.com/questions/22087907/how-to-format-date-in-meteor-template). – David Weldon Sep 10 '15 at 17:36

0 Answers0