JavaScript Get Date Methods
ရက်စွဲအရာဝတ္ထုတစ်ခုမှ အချက်အလက်ရယူရန်အတွက် ဤနည်းလမ်းများကို အသုံးပြုနိုင်သည်။
Method | Description |
---|---|
getFullYear() | Get the year as a four digit number (yyyy) |
getMonth() | Get the month as a number (0-11) |
getDate() | Get the day as a number (1-31) |
getHours() | Get the hour (0-23) |
getMinutes() | Get the minute (0-59) |
getSeconds() | Get the second (0-59) |
getMilliseconds() | Get the millisecond (0-999) |
getTime() | Get the time (milliseconds since January 1, 1970) |
getDay() | Get the weekday as a number (0-6) |
Date.now() | Get the time. ECMAScript 5. |
getTime() နည်းလမ်း
getTime()
နည်းလမ်းသည် ဇန်နဝါရီ ၁ ရက်၊ ၁၉၇၀ ခုနှစ်ကတည်းက မီလီစက္ကန့်အရေအတွက်ကို ပြန်ပေးသည် -
ဥပမာ
const d = new Date();
d.getTime();
getFullYear() နည်းလမ်း
နည်းလမ်းသည် ရက်စွဲ တစ်ခု၏ getFullYear()
နှစ်ကို ဂဏန်းလေးလုံးအဖြစ် ပြန်ပေးသည်-
ဥပမာ
const d = new Date();
d.getFullYear();
getMonth() နည်းလမ်း
getMonth()
နည်းလမ်းသည် ရက်စွဲတစ်ခု၏လကို နံပါတ် (0-11) အဖြစ် ပြန်ပေးသည် -
ဥပမာ
const d = new Date();
d.getMonth();
JavaScript တွင် ပထမလ (ဇန်န၀ါရီ) သည် လနံပါတ် 0 ဖြစ်သောကြောင့် ဒီဇင်ဘာသည် လနံပါတ် 11 သို့ ပြန်ပေးသည်။
နာမည်တစ်ခု၏ array ကိုသုံးနိုင်ပြီး getMonth()
လကို နာမည်တစ်ခုအဖြစ် ပြန်ပြောင်းရန်-
ဥပမာ
const months = ["January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"];
const d = new Date();
let month = months[d.getMonth()];
getDate() နည်းလမ်း
နည်းလမ်းသည် ရက်စွဲ တစ်ခု၏ getDate()
နေ့ရက်ကို နံပါတ် (၁-၃၁) အဖြစ် ပြန်ပေးသည်-။
ဥပမာ
const d = new Date();
d.getDate();
getHours() နည်းလမ်း
နည်းလမ်း သည် getHours()
နံပါတ် (0-23) အဖြစ် ရက်စွဲတစ်ခု၏ နာရီများကို ပြန်ပေးသည်-
ဥပမာ
const d = new Date();
d.getHours();
getMinutes() နည်းလမ်း
နည်းလမ်းသည် ရက်စွဲ တစ်ခု၏ getMinutes()
မိနစ်များကို နံပါတ် (0-59) အဖြစ် ပြန်ပေးသည်-
ဥပမာ
const d = new Date();
d.getMinutes();
getSeconds() နည်းလမ်း
နည်းလမ်းသည် ရက်စွဲ တစ်ခု၏ getSeconds()
စက္ကန့်များကို နံပါတ် (0-59) အဖြစ် ပြန်ပေးသည်-
ဥပမာ
const d = new Date();
d.getSeconds();
getMilliseconds() နည်းလမ်း
နည်းလမ်းသည် ရက်စွဲ တစ်ခု၏ getMilliseconds()
မီလီစက္ကန့်များကို နံပါတ် (0-999) အဖြစ် ပြန်ပေးသည်-
ဥပမာ
const d = new Date();
d.getMilliseconds();
getDay() နည်းလမ်း
getDay()
နည်းလမ်းသည် ရက်စွဲတစ်ခု၏ တစ်ပတ်တာနေ့ကို နံပါတ် (0-6) အဖြစ် ပြန်ပေးသည် -
ဥပမာ
const d = new Date();
d.getDay();
JavaScript တွင်၊ ရက်သတ္တပတ်၏ပထမနေ့ (0) သည် "တနင်္ဂနွေ" ကိုဆိုလိုသည်မှာကမ္ဘာ့နိုင်ငံအချို့တွင်ရက်သတ္တပတ်၏ပထမနေ့ကို "တနင်္လာနေ့" ဟုသတ်မှတ်ထားသော်လည်း၊
နာမည်တစ်ခု၏ array ကိုသုံးနိုင်ပြီး getDay()
အပတ်စဉ်ကို နာမည်တစ်ခုအဖြစ် ပြန်ပြောင်းရန်-
ဥပမာ
const days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];
const d = new Date();
let day = days[d.getDay()];
UTC ရက်စွဲနည်းလမ်းများ
UTC ရက်စွဲနည်းလမ်းများကို UTC ရက်စွဲများ (Universal Time Zone ရက်စွဲများ) နှင့် လုပ်ဆောင်ရန်အတွက် အသုံးပြုပါသည်။
Method | Description |
---|---|
getUTCDate() | Same as getDate(), but returns the UTC date |
getUTCDay() | Same as getDay(), but returns the UTC day |
getUTCFullYear() | Same as getFullYear(), but returns the UTC year |
getUTCHours() | Same as getHours(), but returns the UTC hour |
getUTCMilliseconds() | Same as getMilliseconds(), but returns the UTC milliseconds |
getUTCMinutes() | Same as getMinutes(), but returns the UTC minutes |
getUTCMonth() | Same as getMonth(), but returns the UTC month |
getUTCSeconds() | Same as getSeconds(), but returns the UTC seconds |
JavaScript ရက်စွဲ ကိုးကားချက် အပြည့်အစုံ
ပြီးပြည့်စုံသော ရက်စွဲအကိုးအကားအတွက်၊ ကျွန်ုပ်တို့ထံ သွားပါ။
ပြီးပြည့်စုံသော JavaScript နေ့စွဲအကိုးအကား ။
ရည်ညွှန်းချက်တွင် ရက်စွဲဂုဏ်သတ္တိများနှင့် နည်းလမ်းအားလုံး၏ ဖော်ပြချက်များနှင့် နမူနာများ ပါရှိသည်။