简体   繁体   English

从EJS中的日期对象切片时间戳-Javascript,HTML,Node.js

[英]Slicing timestamp from date object in EJS - Javascript, HTML, Node.js

I'm currently working on looping through and displaying some objects on an EJS webpage. 我目前正在循环浏览并在EJS网页上显示一些对象。 I'm looping through all of them fine and displaying all other data, but I am unable to trim the timestamp off of a date attribute I'm trying to display. 我正在遍历所有这些数据并显示所有其他数据,但是我无法从尝试显示的日期属性中减去时间戳。 It will display the whole date without trimming, but when I try to alter the string, nothing displays. 它会显示整个日期而不进行修剪,但是当我尝试更改字符串时,什么也没有显示。 Here is the code for that part of the EJS file: 这是EJS文件那部分的代码:

<h1 align = "center"><span class="fa fa-map"></span> View Community Maps</h1><br>
<p align="center">Click on a Community Map below to view the full map.</p><br>

<% for (var i=0; i < Maps.length; i++) { %>
    <a href="/viewMap/<%= Maps[i].mapID %>" style="text-decoration: none; color: #333333">
        <div class="well" align="center">
        <script>
            var date = Maps[i].mapDate;
            var dateStringNoTime = date.slice(0, 10); //where I'm trying to slice the timestamp
        </script>

            <h3>Community Map for Floor <%= Maps[i].floorLevel%></h3>
            <p><%=Employee.firstName%> <%=Employee.lastName%></p>
            <p>Week of <script>dateStringNoTime</script></p> // WILL NOT DISPLAY. Displays as "Week of"
        </div>
    </a>
<% } %>

Any help or tips would be appreciated. 任何帮助或提示,将不胜感激。 Thanks! 谢谢! :) :)

像这样的Maps [i] .mapDate.getDate()+“。” + Maps [i] .mapDate.getMonth()+“。” + Maps [i] .mapDate.getFullYear(),但是如果您的month = 1,则您得到0;但是你可以这样做

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM