LoginSignup
6
5

More than 5 years have passed since last update.

javascriptのDateを使って日付を出力する

Last updated at Posted at 2015-01-18

大したことはないのですが・・・JSのDateのgetMonth()とかで、ちょっと混乱したのでメモ。

var date = new Date('2015/1/1');
console.log(date.getMonth()); // 1を期待していたら0
console.log(date.getDay()); // 1を期待していたら4

JSの月は、0〜11で処理されているので、

console.log(date.getMonth() + 1); //これで1

とする必要があります。
で、日付は、getDay()ではなく、getDate()でした・・・(getDay()は曜日)。

console.log(date.getDate()); //これで1
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5