কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে Date.getMonth() ফাংশন


Date.getMonth() ফাংশন

getMonth() মেথড Date অবজেক্টের মাস (০-১১) ফেরত দেয়, যেখানে ০ = জানুয়ারি, ১১ = ডিসেম্বর।

সিনট্যাক্স

dateObj.getMonth()

রিটার্ন মান

মাস ইনডেক্স (০-১১) বা ০ যদি মাস নির্দিষ্ট না করা থাকে।

উদাহরণ

উদাহরণ ১: নির্দিষ্ট তারিখ

const date = new Date('September 26, 1989 12:04:25');
console.log("বছরের মাস: " + date.getMonth()); // 8 (September = 8)

উদাহরণ ২: মাস না থাকলে

const date = new Date('1989 12:04:25'); // মাস নেই
console.log("বছরের মাস: " + date.getMonth()); // 0 (January)

উদাহরণ ৩: বর্তমান মাস

const date = new Date();
console.log("বছরের মাস: " + date.getMonth()); // বর্তমান মাস (০-১১)

গরিষ্ঠ ভুল: getmonth() vs getMonth()

মূল ডকুমেন্টেশনের উদাহরণ ২-এ getmonth() (ছোট হাতের m) ব্যবহার করা হয়েছে, যা ReferenceError দেবে। সঠিক: getMonth()।

মাস নাম পাওয়ার টিপ

const months = ['জানুয়ারি', 'ফেব্রুয়ারি', 'মার্চ', 'এপ্রিল', 'মে', 'জুন',
                'জুলাই', 'আগস্ট', 'সেপ্টেম্বর', 'অক্টোবর', 'নভেম্বর', 'ডিসেম্বর'];
const date = new Date();
console.log(months[date.getMonth()]); // বর্তমান মাসের বাংলা নাম

  1. জাভাস্ক্রিপ্টে Date.getUTCHours() ফাংশন

  2. জাভাস্ক্রিপ্টে Date.getUTCDay() ফাংশন

  3. জাভাস্ক্রিপ্টে Date.toDateString() ফাংশন

  4. জাভাস্ক্রিপ্ট date[@@toPrimitive]() ফাংশন