2014-03-28 91 views
0

我想讓腳本以「m/d/yy」格式顯示昨天的日期。當我使用此代碼:JS - 日期到字符串格式

<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) . 

我在做什麼錯?

+0

10種格式的時間和日期在JS:http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3,也存在這個問題SO具有信息:HTTP://計算器。 COM /問題/ 1056728 /其中,可以-I-找到的文檔上格式化-A-日期中的JavaScript – Goose

回答