I am trying to get the script to display yesterdays date in "m/d/yy" format. When I use this code:
<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>
this is returned:
Here is the comparison report for .
if I put it in without the .format("m/d/yy")
, I get this:
Here is the comparison report for Thu Mar 27 2014 15:42:31 GMT-0700 (Pacific Daylight Time) .
What am I doing wrong?
document.write(yesterday.getMonth() + "/" + yesterday.getDay() + "/" + yesterday.getFullYear())
The date object has many methods for displaying various parts of it. See here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.