2016-11-02 21 views
0

現在の月の最後の日を取得したい。 しかし、私は日付(0)を使用すると、前月の最終日に戻ります。 なぜですか?それは現在の日に相対的ですか?momentJS:先月の最終日を返す日付(0)

var time=moment().tz("America/New_York"); 
console.log(new Date(time)); 
console.log(moment().tz("America/New_York").date(0)); 

出力:

水曜日2016年11月2日午前15時01分43秒GMT + 0530(IST)
月2016年10月31日午後03時01分43秒 GMT + 0530(IST)

次の例に示すように

答えて

3

あなたは、月末を取得するにはendOf()機能を使用することができます。

var time = moment.tz("America/New_York"); 
 
var endOfMonth = time.endOf('month'); 
 
console.log(endOfMonth.format()); 
 
console.log(endOfMonth.date());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.7/moment-timezone-with-data-2010-2020.min.js"></script>

関連する問題