【发布时间】:2021-01-03 01:32:38
【问题描述】:
希望你能帮助我,我需要显示这种格式“2021-01-02”(YYY-MM-DD)。但只显示月和日的 1 位数字。
我的 app.js 中有这个
var moment = require('moment');
getNow: function() {
const today = new Date();
const date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
const date2 = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+(today.getDate()-1);
const dateTime = date;
const dateTime2 = date2;
this.hoy = dateTime;
this.ayer = dateTime2;
我的刀片里有这个
hoy @{{hoy}} - ayer @{{ayer}}
在我的输出中显示这个:
2021 年 1 月 2 日 - 2021 年 1 月 1 日
但我需要格式为“2021-01-02”,因为我需要 2 位数字来比较月份和日期
PD:对不起我的英语。
【问题讨论】: