简体   繁体   English

翡翠模板中的JavaScript日期转换有什么问题?

[英]What is wrong with this javascript date conversion in a jade template?

I am using this in my jade template: 我在我的翡翠模板中使用它:

span.date
        - function convertDate(dateString) {var date = new Date(dateString);return date.getDate()+"."+date.getMonth()+"."+date.getFullYear();}
        | #{convertDate(tile.date)}

while iterating over tiles. 同时遍历瓷砖。

For the input "2016-07-14" the return is "14.6.2016", for "2016-08-09" -> "9.7.2016" etc. 对于输入“ 2016-07-14”,返回值为“ 14.6.2016”,对于“ 2016-08-09”->“ 9.7.2016”等。

Why does a month get lost? 为什么一个月迷路?

date.getMonth() returns the month index, which is 0-based. date.getMonth()返回基于0的月份索引。

To convert it to month position you need to add 1 to its value. 要将其转换为月份位置,您需要在其值上加1

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

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