Java
Date Format
Day of the Week
Programming
Coding

Is there a date format to display the day of the week in java?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Yes. In Java date formatting, the usual pattern letter for a weekday name is E. In modern Java, the best way to use it is through java.time.format.DateTimeFormatter, which is clearer and thread-safe compared with the older SimpleDateFormat API.

The Pattern Letter for Weekday Names

Java date patterns use E to represent the day of the week.

Common forms include:

  • 'E for a short name such as Tue'
  • 'EEEE for a full name such as Tuesday'
  • 'EEEEE for a narrow form in some locales'

A simple example with LocalDate:

java
1import java.time.LocalDate;
2import java.time.format.DateTimeFormatter;
3import java.util.Locale;
4
5public class Main {
6    public static void main(String[] args) {
7        LocalDate date = LocalDate.of(2025, 7, 31);
8
9        DateTimeFormatter full = DateTimeFormatter.ofPattern("EEEE, MMM d, yyyy", Locale.US);
10        DateTimeFormatter shortFmt = DateTimeFormatter.ofPattern("E", Locale.US);
11
12        System.out.println(date.format(full));
13        System.out.println(date.format(shortFmt));
14    }
15}

That prints the weekday in full form in the first case and abbreviated form in the second.

Prefer DateTimeFormatter in New Code

For new Java code, DateTimeFormatter is the right default because it is immutable and thread-safe. It works naturally with modern Java time types such as:

  • 'LocalDate'
  • 'LocalDateTime'
  • 'ZonedDateTime'
  • 'OffsetDateTime'

That makes it a better everyday choice than the older formatting classes.

Locale Changes the Weekday Text

Weekday names depend on locale. The same date can display different day names depending on which locale you use.

java
1import java.time.LocalDate;
2import java.time.format.DateTimeFormatter;
3import java.util.Locale;
4
5public class Main {
6    public static void main(String[] args) {
7        LocalDate date = LocalDate.of(2025, 7, 31);
8
9        System.out.println(date.format(DateTimeFormatter.ofPattern("EEEE", Locale.US)));
10        System.out.println(date.format(DateTimeFormatter.ofPattern("EEEE", Locale.FRANCE)));
11        System.out.println(date.format(DateTimeFormatter.ofPattern("EEEE", Locale.JAPAN)));
12    }
13}

If the output is user-facing, set the locale intentionally instead of relying on the machine default.

Time Zone Can Change the Visible Day

If you are formatting an instant rather than a plain date, the chosen time zone may change the visible weekday. That matters for timestamps near midnight.

java
1import java.time.Instant;
2import java.time.ZoneId;
3import java.time.format.DateTimeFormatter;
4import java.util.Locale;
5
6public class Main {
7    public static void main(String[] args) {
8        Instant instant = Instant.parse("2025-07-31T01:30:00Z");
9        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("EEEE HH:mm z", Locale.US);
10
11        System.out.println(fmt.withZone(ZoneId.of("America/Toronto")).format(instant));
12        System.out.println(fmt.withZone(ZoneId.of("Asia/Tokyo")).format(instant));
13    }
14}

For reporting, notifications, and scheduling logic, this distinction is important. The day of week is not just a formatting question if the underlying moment is being viewed in different zones.

Legacy SimpleDateFormat Still Uses the Same Idea

Older Java code often uses SimpleDateFormat, and it uses the same E pattern.

java
1import java.text.SimpleDateFormat;
2import java.util.Date;
3import java.util.Locale;
4
5public class Main {
6    public static void main(String[] args) {
7        SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMM d, yyyy", Locale.US);
8        System.out.println(sdf.format(new Date()));
9    }
10}

This still works, but SimpleDateFormat is mutable and not thread-safe. For shared formatter usage in modern code, DateTimeFormatter is much safer.

Use DayOfWeek for Logic

Formatting is for presentation. If your program logic needs to know whether a date is Monday, Friday, or weekend, use structured date APIs rather than inspecting formatted strings.

For example, use date.getDayOfWeek() for logic and use DateTimeFormatter only when you are preparing text for output.

That keeps logic robust and localization-friendly.

Common Pitfalls

The most common mistake is using the wrong pattern letters and expecting a weekday name from something other than E.

Another pitfall is forgetting about locale and then getting different output on different environments. Developers also often ignore time zone when formatting instants near midnight, which can make the displayed weekday look “wrong” even though the formatter is behaving correctly.

Finally, avoid using formatted strings for weekday logic. Compare structured date values instead.

Summary

  • Java uses E to format weekday names.
  • 'DateTimeFormatter is the recommended modern API for this task.'
  • Use E for short names and EEEE for full names.
  • Set locale and time zone explicitly when the output must be stable.
  • Use DayOfWeek for logic and formatted strings only for presentation.

Course illustration
Course illustration

All Rights Reserved.