在文本框中显示当前日期前 270 天

display 270 days prior to the current date in text box

本文关键字:当前日期 显示 文本      更新时间:2023-09-26

>我正在尝试加载今天之前的 270 日期。我尝试了以下代码,但看起来有问题。

var d = new Date();
alert(d.setDate(d.getDate() - 2).toString()); //2 is just that I tried some number

我也想以以下格式显示 dd/mm/yyyy。谢谢

DATEOBJ.getDate会返回您的日期

DATEOBJ.getMonth将返回月份(0-11)

DATEOBJ.getFullYear将返回年份(年 4 位数字

function pad(n) {
  return (n < 10) ? ("0" + n) : n;
}
var d = new Date();
d.setDate(d.getDate() - 270);
alert(d);
alert(pad(d.getDate()) + '/' + pad(d.getMonth() + 1) + '/' + d.getFullYear());