Date.prototype.getMonth() - Local timeの月を返す
Date.prototype.getMonth()は、インスタンスから、Local time(端末の時間設定)に従った「月」を取得するメソッドです。月は1からではなく、0から数える点にご注意下さい。
概要
説明
Date.prototype.getMonth ( )
Local timeにおける月を表す0〜11の数値を返す。
デモ
Date.prototype.getMonth()のデモです。
<!-- このコードは編集できます。 -->
<!DOCTYPE html>
<html>
<head>
<style>
body {
white-space: pre-wrap ;
}
</style>
</head>
<body>
<script>
/** try it! **/
var date = new Date( 2017, 4, 10, 12, 10, 30, 15 ) ;
var a = date.getMonth() ;
/** try it! **/
var results = { a:a, } ;
for( var name in results ) {
console.log( name, results[name] ) ;
document.body.appendChild( new Text( name + " = " + JSON.stringify( results[name] ) + "\n" ) ) ;
}
</script>
</body>
</html>
サポート状況
Chrome | Firefox | Safari | Edge | IE | Opera | iOS Safari | Android |
---|---|---|---|---|---|---|---|
● | ● | ● | ● | ● | ● | ● | ● |
関連記事
- Date.prototype.toLocaleDateString()
- Date.prototype.toLocaleDateString()は、インスタンスの日付部分までをローカライズした文字列に変換するメソッドです。
- Date.prototype.toDateString()
- Date.prototype.toDateString()は、インスタンスの日付部分までを文字列に変換するメソッドです。表記形式は英語なので、日本では利用機会は少ないと思います。
- Date.prototype.toLocaleString()
- Date.prototype.toLocaleString()は、インスタンスの日時をローカライズした文字列に変換するメソッドです。
- Date.prototype.getFullYear()
- Date.prototype.getFullYear()は、インスタンスから、Local time(端末の時間設定)に従った「年」を取得するメソッドです。