JavaScript · Lesson 18 / 32 · தமிழ்
JavaScript Dates
கருத்தைப் புரிந்துகொள்ளுங்கள். Code-ஐ மாற்றி இயக்குங்கள். ஒரு சிறிய பயிற்சியால் கற்றதை உறுதி செய்யுங்கள்.
மூலப் பாட விளக்கங்கள் தமிழில் உள்ளன. கூடுதல் concept, practice மற்றும் answer notes ஆங்கிலத்தில் உள்ளன.
முக்கியக் கருத்து
A Date represents an instant in time. Local display depends on the environment, so use explicit UTC values when you need a predictable example.
Learning goal: Explain what the example does, predict its result, and change it to solve the practice task.
விரிவான விளக்கங்கள்
JavaScript-ல Date Object
Date object dates மற்றும் times-உடன் work பண்ண use ஆகும். Internally January 1, 1970-ல இருந்து milliseconds count பண்றது (Unix epoch).
const now = new Date(); // current date & time
const specific = new Date("2024-01-15"); // ISO string-ல இருந்து
const fromParts = new Date(2024, 0, 15); // year, month(0-indexed), day
console.log(Date.now()); // milliseconds-ல current timeDate Components Get பண்றது
const d = new Date();
d.getFullYear(); // 2024
d.getMonth(); // 0-11 (0 = January!)
d.getDate(); // 1-31
d.getDay(); // 0-6 (0 = Sunday)
d.getHours(); // 0-23
d.getMinutes(); // 0-59கவனம்! Months 0-indexed: January = 0, December = 11.
Date Formatting
const d = new Date();
d.toISOString(); // "2024-01-15T10:30:00.000Z"
d.toLocaleDateString(); // "1/15/2024"
// Custom formatting
const formatter = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
day: "numeric"
});
console.log(formatter.format(d)); // "January 15, 2024"முழுமையான உதாரணம்
Run this complete index.js program in the JavaScript console editor below. The earlier reference fragments may need a browser page or other surrounding setup.
const lessonDate = new Date("2026-01-15T10:00:00Z");
console.log(lessonDate.toISOString());
console.log(lessonDate.getUTCFullYear());
console.log(lessonDate.getUTCMonth() + 1);எதிர்பார்க்கும் முடிவைப் பாருங்கள்
2026-01-15T10:00:00.000Z 2026 1
மாற்றி இயக்கிப் பாருங்கள்
Load the example, change a value, predict the output, and run it again. Use the console output to check your reasoning.
Editor load ஆனதும் code-ஐ ஏற்றி Run அழுத்துங்கள்.
OneCompiler என்ற இலவச வெளிப்புற சேவை code-ஐ இயக்குகிறது. Run செய்யும் code அங்கு அனுப்பப்படும். தனிப்பட்ட தகவல்கள் அல்லது secret keys உள்ளிட வேண்டாம்.
சிறிய பயிற்சி
Practice challenge
Change the timestamp to 2026-02-01T00:00:00Z.
விடை மற்றும் விளக்கம்
The UTC month plus one becomes 2 and the ISO output is 2026-02-01T00:00:00.000Z.
தவிர்க்க வேண்டிய தவறு: getMonth and getUTCMonth are zero-based. Avoid ambiguous date strings such as 01/02/2026.
அடுத்த பாடத்திற்குத் தயாரா?
- Explain the example in your own words.
- Complete the challenge before revealing its answer.
- Describe the common mistake and how to avoid it.