JavaScript Tanggal setBulan()
Contoh
Atur bulan menjadi 4 (Mei):
const d = new Date();
d.setMonth(4);
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Metode setMonth() menyetel bulan dari objek tanggal.
Catatan: Januari adalah 0, Februari adalah 1, dan seterusnya.
Metode ini juga dapat digunakan untuk mengatur hari dalam sebulan.
Dukungan Peramban
setMonth()
adalah fitur ECMAScript1 (ES1).
ES1 (JavaScript 1997) didukung penuh di semua browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Date.setMonth(month, day)
Nilai Parameter
Parameter | Description |
---|---|
month | Required. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
Detail Teknis
Nilai Kembali: | Angka, mewakili jumlah milidetik antara objek tanggal dan tengah malam 1 Januari 1970 |
---|---|
Versi JavaScript: | ECMAScript 1 |
Lebih Banyak Contoh
Contoh
Atur bulan ke 4 (Mei) dan hari ke 20:
const d = new Date();
d.setMonth(4, 20);
Contoh
Setel tanggal ke hari terakhir bulan lalu:
const d = new Date();
d.setMonth(d.getMonth(), 0);