JavaScript Get Date Methods
The new Date() Constructor
জাভাস্ক্রিপ্টে, তারিখ অবজেক্ট নতুন Date() দিয়ে তৈরি করা হয়।
new Date() বর্তমান তারিখ এবং সময় সহ একটি তারিখ অবজেক্ট প্রদান করে।
Get the Current Time
const date = new Date();
Date Get Methods
| Method | Description |
|---|---|
| getFullYear() | Get year as a four digit number (yyyy) |
| getMonth() | Get month as a number (0-11) |
| getDate() | Get day as a number (1-31) |
| getDay() | Get weekday as a number (0-6) |
| getHours() | Get hour (0-23) |
| getMinutes() | Get minute (0-59) |
| getSeconds() | Get second (0-59) |
| getMilliseconds() | Get millisecond (0-999) |
| getTime() | Get time (milliseconds since January 1, 1970) |
নোট 1:
উপরের প্রাপ্ত পদ্ধতিগুলি স্থানীয় সময় ফেরত দেয়।
সর্বজনীন সময় (UTC) এই পৃষ্ঠার নীচে নথিভুক্ত করা হয়েছে।
নোট 2:
পাওয়া পদ্ধতি বিদ্যমান তারিখ বস্তু থেকে তথ্য ফেরত.
একটি তারিখ বস্তুতে, সময় ধ্রুবক। "ঘড়ি" "চলছে না"।
তারিখ অবজেক্টের সময় বর্তমান সময়ের মতো নয়।
The getFullYear() Method
getFullYear() পদ্ধতিটি একটি তারিখের বছরকে চার-সংখ্যার সংখ্যা হিসাবে প্রদান করে:
উদাহরণ
const d = new Date("2021-03-25");
d.getFullYear();
const d = new Date();
d.getFullYear();
সতর্কতা !
পুরানো জাভাস্ক্রিপ্ট কোড অ-মানক getYear() পদ্ধতি ব্যবহার করতে পারে।
getYear() একটি 2-সংখ্যার বছর ফেরত দিতে হবে।
getYear() বাতিল করা হয়েছে। এটা ব্যবহার করবেন না!
The getMonth() Method
getMonth() পদ্ধতি একটি পূর্ণসংখ্যা (0-11) হিসাবে একটি তারিখের মাস প্রদান করে।
দ্রষ্টব্য:
জাভাস্ক্রিপ্টে, জানুয়ারি মাস হল 0 নম্বর, ফেব্রুয়ারি হল 1 নম্বর, ...
অবশেষে, ডিসেম্বর মাস 11 নম্বর।
উদাহরণ
const d = new Date("2021-03-25");
d.getMonth();
const d = new Date();
d.getMonth();
দ্রষ্টব্য:
একটি নাম হিসাবে মাস ফেরত দিতে নামের একটি অ্যারে ব্যবহার করা যেতে পারে:
উদাহরণ
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const d = new Date("2021-03-25");
let month = months[d.getMonth()];
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const d = new Date();
let month = months[d.getMonth()];
The getDate() Method
getDate() পদ্ধতি একটি পূর্ণসংখ্যা (1-31) হিসাবে একটি তারিখের দিন প্রদান করে:
উদাহরণ
const d = new Date("2021-03-25");
d.getDate();
const d = new Date();
d.getDate();
The getHours() Method
getHours() পদ্ধতিটি একটি সংখ্যা হিসাবে একটি তারিখের ঘন্টা প্রদান করে (0-23):
উদাহরণ
const d = new Date("2021-03-25");
d.getHours();
const d = new Date();
d.getHours();
The getMinutes() Method
getMinutes() পদ্ধতি একটি পূর্ণসংখ্যা (0-59) হিসাবে একটি তারিখের মিনিট ফেরত দেয়:
উদাহরণ
const d = new Date("2021-03-25");
d.getMinutes();
const d = new Date();
d.getMinutes();
The getSeconds() Method
getSeconds() পদ্ধতি একটি পূর্ণসংখ্যা (0-59) হিসাবে একটি তারিখের সেকেন্ড প্রদান করে:
উদাহরণ
const d = new Date("2021-03-25");
d.getSeconds();
const d = new Date();
d.getSeconds();
The getMilliseconds() Method
getMilliseconds() পদ্ধতি একটি পূর্ণসংখ্যা (0-999) হিসাবে একটি তারিখের মিলিসেকেন্ড প্রদান করে:
উদাহরণ
const d = new Date("2021-03-25");
d.getMilliseconds();
const d = new Date();
d.getMilliseconds();
The getDay() Method
getDay() পদ্ধতি একটি পূর্ণসংখ্যা (0-6) হিসাবে একটি তারিখের সপ্তাহের দিন প্রদান করে।
দ্রষ্টব্য:
জাভাস্ক্রিপ্টে, সপ্তাহের প্রথম দিন (দিন 0) রবিবার।
বিশ্বের কিছু দেশ সোমবারকে সপ্তাহের প্রথম দিন হিসেবে বিবেচনা করে।
উদাহরণ
const d = new Date("2021-03-25");
d.getDay();
const d = new Date();
d.getDay();
দ্রষ্টব্য:
নামের একটি অ্যারে এবং getDay() সপ্তাহের দিনটিকে একটি নাম হিসাবে ফেরত দিতে ব্যবহার করা যেতে পারে:
উদাহরণ
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const d = new Date("2021-03-25");
let day = days[d.getDay()];
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const d = new Date();
let day = days[d.getDay()];
The getTime() Method
getTime() পদ্ধতিটি জানুয়ারী 1, 1970 থেকে মিলিসেকেন্ডের সংখ্যা প্রদান করে:
উদাহরণ
const d = new Date("1970-01-01");
d.getTime();
const d = new Date("2021-03-25");
d.getTime();
const d = new Date();
d.getTime();
The Date.now() Method
Date.now() 1, 1970 .
উদাহরণ
let ms = Date.now();
01/01/1970 সাল থেকে বছরের সংখ্যা গণনা করুন:
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;
let years = Math.round(Date.now() / year);
Date.now() Date static .
myDate.now() .
সিনট্যাক্স সবসময় Date.now() হয়।
UTC Date Get Methods
| Method | Same As | Description |
|---|---|---|
| getUTCDate() | getDate() | Returns the UTC date |
| getUTCFullYear() | getFullYear() | Returns the UTC year |
| getUTCMonth() | getMonth() | Returns the UTC month |
| getUTCDay() | getDay() | Returns the UTC day |
| getUTCHours() | getHours() | Returns the UTC hour |
| getUTCMinutes() | getMinutes() | Returns the UTC minutes |
| getUTCSeconds() | getSeconds() | Returns the UTC seconds |
| getUTCMilliseconds() | getMilliseconds() | Returns the UTC milliseconds |
UTC পদ্ধতি UTC সময় (সমন্বিত সর্বজনীন সময়) ব্যবহার করে।
UTC সময় GMT (গ্রিনউইচ গড় সময়) এর মতোই।
স্থানীয় সময় এবং UTC সময়ের মধ্যে পার্থক্য 24 ঘন্টা পর্যন্ত হতে পারে।
The getTimezoneOffset() Method
getTimezoneOffset() পদ্ধতি স্থানীয় সময় এবং UTC সময়ের মধ্যে পার্থক্য (মিনিটের মধ্যে) প্রদান করে:
উদাহরণ
let diff = d.getTimezoneOffset();
Learn More:
- JavaScript Date Tutorial
- JavaScript Date Formats
- JavaScript Date Set Methods
- JavaScript Date Reference
Exercise
getDay() পদ্ধতির রিটার্ন মান কি?