Course contentsShow
← Java
Lesson 1889 of 2,87038. Date and Time API (java.time)Free lesson

Pattern Symbols: Date Components (y, M, d, E, D)

Understanding year, month, day-of-month, day-of-week, and day-of-year pattern symbols and their letter count variations.

Pattern Symbols: Date Components (y, M, d, E, D)

You'll learn how to use the five essential date pattern symbols to format years, months, days-of-month, days-of-week, and days-of-year.

Understanding Pattern Symbols

When creating custom DateTimeFormatter patterns with ofPattern, you use letter symbols to represent different date components. Think of these symbols like placeholders in a template—each letter tells the formatter which part of the date to display and how many of those letters controls the output style.

The Five Core Date Symbols

y - Year

  • y or yy: Two-digit year (e.g., "24" for 2024)
  • yyyy: Four-digit year (e.g., "2024")

M - Month

  • M: Numeric month without padding (e.g., "3" for March)
  • MM: Numeric month with padding (e.g., "03")
  • MMM: Short text month (e.g., "Mar")
  • MMMM: Full text month (e.g., "March")

d - Day of Month

  • d: Day without padding (e.g., "5")
  • dd: Day with padding (e.g., "05")

E - Day of Week

  • E, EE, or EEE: Short text (e.g., "Tue")
  • EEEE: Full text (e.g., "Tuesday")

D - Day of Year

  • D: Day number in the year (1-365/366)
  • DDD: Three-digit padded (e.g., "001" for January 1st)

Pattern Example

The pattern "yyyy-MM-dd (EEEE)" would format March 5, 2024 as "2024-03-05 (Tuesday)", while "E, MMM d, yy" produces "Tue, Mar 5, 24".

Key Takeaway: The letter indicates which date component, and the count of repeated letters controls formatting style—more letters generally mean more verbose output (text vs. numbers, padding, full vs. abbreviated).