简体   繁体   English

如何显示使用JavaScript从数据库正确检索的日期

[英]How to show date properly retrieved from database, using JavaScript

i've been busy on a project for school to make an app using Node.js and a mysql database. 我一直在忙着一个学校项目,使用Node.js和mysql数据库制作应用程序。 I got stuck at showing the date properly i was retrieving from the database. 我被困在正确显示我从数据库中检索的日期。 This is the code for showing the data from the EJS file: 这是用于显示EJS文件中数据的代码:

<table>
    <tr>
        <th>Titel</th>
        <th>Locatie</th>
        <th>Datum</th>
        <th>Naam</th>
        <th>Waardering</th>
    </tr>
        <% } %>

        <% for (var i = 0; i < pictures.length; i++) { %>
    <tr>

        <td><%= pictures[i].titel %></td>
        <td><%= pictures[i].locatie %></td>
        <td><%= pictures[i].datum %></td>
        <td><%= pictures[i].naam %></td>
        <td><%= pictures[i].waardering %></td>
        <% } %>
    </tr>                   
</table>

This is what i get: 这就是我得到的:

data from database 来自数据库的数据

I just want to show the day, month & year 我只想显示日期,月份和年份

Thanks for your help 谢谢你的帮助

You have valid ISO dates that can be passed directly to new Date . 您具有可以直接传递给new Date有效ISO new Date

In your route, parse the dates with something like this before you send it to the template 在您的路线中,使用类似以下的方法解析日期,然后将其发送到模板

app.get('something', function(res, req, next) {

    var pictures = get_from_mysql('something');

    pictures.forEach(function(pic) {
        var date  = new Date(pic.datum);
        pic.datum = date.getDate + '/' + (date.getMonth + 1) + '/' + date.getFullYear();
    });

    res.render('template.ejs', {pictures:pictures})

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 javascript 正确显示数据库中的日期 - properly display date from database using javascript 如何使用php从mysql检索数据并在javascript上显示? - How to retrieved data from mysql using php and show it on javascript? 如何通过使用htlm和Java脚本从Firebase数据库检索的纬度和经度在地图上显示标记 - How to show a marker on map by using latitude and longitude retrieved from firebase database in htlm and java script 显示使用JavaScript从MySQL数据库检索的Blob数据 - Display Blob data retrieved from MySQL Database using JavaScript 如何通过使用PHP,javascript和html单击从数据库中检索到的数据来编辑每行属性 - how each row attributes can be edited by clicking on retrieved data from the database using PHP, javascript and html 如何在 Javascript 代码中显示 Laravel 从数据库中检索到的结果 - How to show Laravel retrieved results from the DB in a Javascript code 如何使用JavaScript在数据库中添加引用计数的文本框? - How to add a text box with the reference count retrieved in the database using javascript? 从数据库中检索数据时如何停止javascript加载器 - How to stop the javascript loader when the data retrieved from the database 如何使用php从mysql数据库中分页检索到的数据? - how to paginate the retrieved data from mysql database by using php? 我使用jQuery从数据库中检索了一个日期。 检索到的值为“ 2012-01-10 00:00:00”(包括引号) - I retrieved a date from my database using jQuery. The retrieved value is “2012-01-10 00:00:00” (quotes included)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM