Java Date — தமிழ்

</>Coding Tamilan.← Java course & curriculum
Java Masterclass · Lesson 39 / 50 · தமிழ்

Java Date

Model dates with the right abstraction.

Step-by-step explanationsRunnable JavaPractice + answer

முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.

இந்தப் பாடத்தில்…

  • Explain the key idea behind Date and Time.
  • Read and run a complete example, then predict what changes.
  • Recognize the topic-specific mistake discussed below.
01 / The concept

அடிப்படையைப் புரிந்துகொள்ளுங்கள்

java.time provides types with distinct purposes. LocalDate is a date without a time or time zone. LocalDateTime also has no time zone. Choose Instant or a zoned type when you need a point on the timeline or a location-specific time. Fixed dates make examples reproducible.

02 / Step by step

விரிவான விளக்கங்கள்

Java Dates

Java-ல dates-ஐ work பண்றதுக்கு java.time package use பண்றோம் (Java 8-ல introduce ஆச்சு).

Key classes:

  • LocalDate — date மட்டும் (time இல்ல): 2024-03-15
  • LocalTime — time மட்டும் (date இல்ல): 14:30:00
  • LocalDateTime — date மற்றும் time: 2024-03-15T14:30:00
  • DateTimeFormatter — date/time-ஐ format பண்றதுக்கு

Current Date மற்றும் Time

Current date/time-ஐ now() method-ல get பண்ணலாம்:

Common Date Format Patterns

PatternMeaningExample output
yyyy4-digit year2025
MM2-digit month (01–12)04
dd2-digit day (01–31)14
HHHour in 24-hour format15
mmMinutes (00–59)30
EEEEFull day nameMonday
MMMMFull month nameApril
Java reference fragmentJAVA
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter f1 = DateTimeFormatter.ofPattern("dd/MM/yyyy");
DateTimeFormatter f2 = DateTimeFormatter.ofPattern("EEEE, MMMM dd yyyy");
DateTimeFormatter f3 = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");

System.out.println(now.format(f1));  // 14/04/2025
System.out.println(now.format(f2));  // Monday, April 14 2025
System.out.println(now.format(f3));  // 14-04-2025 15:30:05

Modern Java-வில் date/time-க்கு எந்த class prefer செய்வோம்?

  1. java.util.Date
  2. java.util.Calendar
  3. java.time.LocalDate (Java 8+)
  4. java.sql.Date
Reveal answer / விடை

java.time.LocalDate (Java 8+)

`java.time` package (Java 8+) immutable, thread-safe, மற்றும் intuitive. `LocalDate`, `LocalDateTime`, `ZonedDateTime` — modern applications-ல் இதையே பயன்படுத்தவும். Old `Date` class deprecated.

03 / Read and predict

முழுமையான உதாரணம்

This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.

Main.java · complete runnable exampleJAVA
import java.time.LocalDate;
public class Main {
    public static void main(String[] args) throws Exception {
        LocalDate start = LocalDate.of(2026, 1, 1);
        System.out.println(start.plusDays(7));
        System.out.println(start);
    }
}
Predict first. Then reveal the expected output / வெளியீடு
2026-01-08
2026-01-01

The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.

04 / Learn by changing

Change it. Run it. Understand it.

Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.

Open Java editor ↗
After the editor loads, choose Load this lesson example, then press RUN.

Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.

05 / Your turn

நீங்களே முயற்சி செய்யுங்கள்

Practice challenge

Store start.plusDays(7) back into start and print it.

Reveal the answer and reasoning / விடை

The variable then refers to the later date. The original LocalDate object was not modified.

தவிர்க்க வேண்டிய தவறு: java.time objects such as LocalDate are immutable. Calling plusDays without using the return value does not change the variable.

பாடத்தின் சுருக்கம்

  • Explain the example without reading the output first.
  • Make the change requested in the practice task.
  • Describe why the result changed—or why compilation failed.

Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.

Coding Tamilan · Understand the idea. Try the code. Build the habit.