JavaScript Get Date Methods

JavaScript தேதி பெறும் முறைகள் பற்றி அறிக

JavaScript Get Date Methods

The new Date() Constructor

JavaScript இல், தேதி பொருள்கள் new 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:

மேலே உள்ள get முறைகள் Local நேரத்தை வழங்குகின்றன.

Universal time (UTC) இந்தப் பக்கத்தின் கீழே ஆவணப்படுத்தப்பட்டுள்ளது.

📝 குறிப்பு 2:

get முறைகள் இருக்கும் தேதி பொருள்களிலிருந்து தகவலை வழங்குகின்றன.

ஒரு தேதி பொருளில், நேரம் நிலையானது. "கடிகாரம்" "இயங்கவில்லை".

தேதி பொருளில் உள்ள நேரம் தற்போதைய நேரத்தைப் போல இல்லை.

The getFullYear() Method

getFullYear() முறை ஒரு தேதியின் ஆண்டை நான்கு இலக்க எண்ணாக வழங்குகிறது:

எடுத்துக்காட்டுகள்

const d = new Date("2021-03-25");
d.getFullYear();
const d = new Date();
d.getFullYear();

⚠️ எச்சரிக்கை!

பழைய JavaScript குறியீடு தரமற்ற getYear() முறையைப் பயன்படுத்தலாம்.

getYear() 2-இலக்க ஆண்டை வழங்க வேண்டும்.

getYear() காலாவதியானது. அதைப் பயன்படுத்த வேண்டாம்!

The getMonth() Method

getMonth() முறை ஒரு தேதியின் மாதத்தை எண்ணாக (0-11) வழங்குகிறது.

📝 குறிப்பு:

JavaScript இல், ஜனவரி என்பது மாத எண் 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) வழங்குகிறது.

📝 குறிப்பு:

JavaScript இல், வாரத்தின் முதல் நாள் (நாள் 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();

1970/01/01 முதல் ஆண்டுகளின் எண்ணிக்கையைக் கணக்கிடுங்கள்:

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 நேரத்தைப் (Coordinated Universal Time) பயன்படுத்துகின்றன.

UTC நேரம் GMT (Greenwich Mean Time) போன்றதே.

Local நேரத்திற்கும் UTC நேரத்திற்கும் இடையே உள்ள வேறுபாடு 24 மணி நேரம் வரை இருக்கலாம்.

The getTimezoneOffset() Method

getTimezoneOffset() முறை local நேரத்திற்கும் UTC நேரத்திற்கும் இடையே உள்ள வேறுபாட்டை (நிமிடங்களில்) வழங்குகிறது:

எடுத்துக்காட்டு

let diff = d.getTimezoneOffset();

Learn More:

Exercise

getDay() முறையின் வருவாய் மதிப்பு என்ன?

getDay() எதை வழங்குகிறது?

A number between 1 and 31
✗ தவறு! 1-31 என்பது getDate() முறையின் வரம்பு, வார நாள் அல்ல.
A number between 0 and 30
✗ தவறு! getDate() 1-31 வரம்பில் இயங்குகிறது, மேலும் 0-30 வரம்பு getDay() க்கு உண்மையல்ல.
A number between 1 and 7
✗ தவறு! JavaScript இல் வார நாட்கள் 0-6 வரம்பில் உள்ளன, 1-7 அல்ல.
A number between 0 and 6
✓ சரி! getDay() 0-6 வரம்பில் ஒரு எண்ணை வழங்குகிறது, அங்கு 0=ஞாயிறு, 1=திங்கள், 2=செவ்வாய், 3=புதன், 4=வியாழன், 5=வெள்ளி, 6=சனி.