JavaScript Set Date Methods
Set Date முறைகள் ஒரு தேதி பொருளுக்கான தேதி மதிப்புகளை (ஆண்டுகள், மாதங்கள், நாட்கள், மணிநேரம், நிமிடங்கள், வினாடிகள், மில்லிவினாடிகள்) அமைக்க உங்களை அனுமதிக்கின்றன.
Set Date Methods
Set Date முறைகள் ஒரு தேதியின் ஒரு பகுதியை அமைக்கப் பயன்படுத்தப்படுகின்றன:
| Method | Description |
|---|---|
| setDate() | Set the day as a number (1-31) |
| setFullYear() | Set the year (yyyy) |
| setHours() | Set the hour (0-23) |
| setMilliseconds() | Set the milliseconds (0-999) |
| setMinutes() | Set the minutes (0-59) |
| setMonth() | Set the month (0-11) |
| setSeconds() | Set the seconds (0-59) |
| setTime() | Set the time (milliseconds since January 1, 1970) |
The setFullYear() Method
setFullYear() முறை ஒரு தேதி பொருளின் ஆண்டை அமைக்கிறது. இந்த எடுத்துக்காட்டில் 2020:
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setFullYear(2020);
setFullYear() முறை விருப்பத்திற்குரிய மாதம் மற்றும் நாளையும் அமைக்கலாம்:
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setFullYear(2020, 11, 3);
The setMonth() Method
setMonth() முறை ஒரு தேதி பொருளின் மாதத்தை அமைக்கிறது (0-11):
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setMonth(11);
The setDate() Method
setDate() முறை ஒரு தேதி பொருளின் நாளை அமைக்கிறது (1-31):
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setDate(15);
setDate() முறை ஒரு தேதிக்கு நாட்களைச் சேர்க்கவும் பயன்படுத்தப்படலாம்:
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setDate(d.getDate() + 50);
குறிப்பு:
நாட்களைச் சேர்ப்பது மாதம் அல்லது ஆண்டை மாற்றினால், Date பொருளால் மாற்றங்கள் தானாகவே கையாளப்படும்.
The setHours() Method
setHours() முறை ஒரு தேதி பொருளின் மணிநேரங்களை அமைக்கிறது (0-23):
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setHours(22);
setHours() முறை நிமிடங்கள் மற்றும் வினாடிகளையும் அமைக்கப் பயன்படுத்தலாம்.
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setHours(22, 10, 20);
The setMinutes() Method
setMinutes() முறை ஒரு தேதி பொருளின் நிமிடங்களை அமைக்கிறது (0-59):
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setMinutes(30);
The setSeconds() Method
setSeconds() முறை ஒரு தேதி பொருளின் வினாடிகளை அமைக்கிறது (0-59):
எடுத்துக்காட்டு
const d = new Date("January 01, 2025");
d.setSeconds(30);
Compare Dates
தேதிகளை எளிதாக ஒப்பிடலாம்.
பின்வரும் எடுத்துக்காட்டு இன்றைய தேதியை ஜனவரி 14, 2100 உடன் ஒப்பிடுகிறது:
எடுத்துக்காட்டு
let text = "";
const today = new Date();
const someday = new Date();
someday.setFullYear(2100, 0, 14);
if (someday > today) {
text = "Today is before January 14, 2100.";
} else {
text = "Today is after January 14, 2100.";
}
குறிப்பு:
JavaScript மாதங்களை 0 முதல் 11 வரை எண்ணுகிறது. ஜனவரி 0. டிசம்பர் 11.
Learn More:
- JavaScript Date Tutorial
- JavaScript Date Formats
- JavaScript Date Get Methods
- JavaScript Date Reference
Exercise
setDate() முறையில் வாதத்தின் எதிர்பார்க்கப்படும் வடிவம் என்ன?