Answer the question
In order to leave comments, you need to log in
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();
});
});
})
}
};
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})
})
});
<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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question