H
H
hollanditkzn2017-09-22 16:15:12
JavaScript
hollanditkzn, 2017-09-22 16:15:12

How to change datetime format when outputting from db to render?

I have a question like this, it comes from the datetime database in this format 2017-09-29T21:00:00.000Z and in rendering it outputs like this Sat Sep 30 2017 00:00:00 GMT+0300 (Moscow time (winter))
I don’t understand where and how to write the code so that I can display 09/30/2017 00:00 in this form
I don’t write a connection to mysql, since it is most likely not needed here.
In the model

let Tasks = {
    list: function(){
        return new Promise((resolve, reject) => {
            pool.getConnection(function(err, connection){
                if (err) console.log(reject(err));

                connection.query('SELECT * FROM tasks',
                    function(err, rows){
                        if (err || !rows){
                            reject(err);
                        }

                        resolve(rows);
                        connection.release();
                    });
            });
        })
    }
};

In the router
app.engine('hbs', templating.handlebars);
app.set('view engine', 'hbs');
app.set('views', __dirname + '/views');

app.get('/', function (req, res) {
    Task.list().then(tasks => {
        res.render('main', {tasks})
    })
});

And in the view
<table>
            <tr>
                <th></th>
                <th>Задача</th>
                <th>Приоритет</th>
                <th>Срок</th>
            </tr>
            {{#each tasks}}
            <tr>
                <td></td>
                <td>{{this.text}}</td>
                <td>{{this.prioritet}}</td>
                <td>{{this.srok}}</td>
            </tr>
            {{/each}}
        </table>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2017-09-22
@hollanditkzn

The date display format is a task for the view layer. Perhaps the template engine used has ready-made tools for working with date formatting, it may be possible to connect something like momentjs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question