我正在尝试让脚本以"m/d/yy"格式显示昨天的日期。当我使用这个代码:
<p>
Here is the report for
<script>
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
document.write(yesterday.format("m/d/yy"));
</script>
.
</p>
这是返回的:
Here is the comparison report for .
如果我把它放在没有.format("m/d/yy")
的地方,我会得到这个:
Here is the comparison report for Thu Mar 27 2014 15:42:31 GMT-0700 (Pacific Daylight Time) .
我做错了什么?
document.write(yesterday.getMonth() + "/" + yesterday.getDay() + "/" + yesterday.getFullYear())
date对象有许多显示其各个部分的方法。请参见此处:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date