|
12 | 12 | import java.time.*;
|
13 | 13 | import java.time.format.DateTimeFormatter;
|
14 | 14 | import java.time.format.DateTimeParseException;
|
| 15 | +import java.time.format.TextStyle; |
15 | 16 | import java.time.temporal.TemporalAdjusters;
|
16 | 17 | import java.util.*;
|
17 | 18 | import java.util.concurrent.TimeUnit;
|
@@ -1600,4 +1601,58 @@ public static Date roundUpToNextHour(Date date, int hour) {
|
1600 | 1601 | LocalDateTime roundedUpTime = local.withMinute(0).withSecond(0);
|
1601 | 1602 | return Time4j.transform(roundedUpTime);
|
1602 | 1603 | }
|
| 1604 | + |
| 1605 | + /** |
| 1606 | + * Gets the day of the week for a given {@link Calendar} instance. |
| 1607 | + * |
| 1608 | + * @param calendar The {@link Calendar} instance. |
| 1609 | + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). |
| 1610 | + */ |
| 1611 | + public static String getDayOfWeek(Calendar calendar) { |
| 1612 | + if (calendar == null) { |
| 1613 | + return ""; |
| 1614 | + } |
| 1615 | + SimpleDateFormat format = new SimpleDateFormat("EEEE"); |
| 1616 | + return format.format(calendar.getTime()); |
| 1617 | + } |
| 1618 | + |
| 1619 | + /** |
| 1620 | + * Gets the day of the week for a given {@link Date} instance. |
| 1621 | + * |
| 1622 | + * @param date The {@link Date} instance. |
| 1623 | + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). |
| 1624 | + */ |
| 1625 | + public static String getDayOfWeek(Date date) { |
| 1626 | + if (date == null) { |
| 1627 | + return ""; |
| 1628 | + } |
| 1629 | + SimpleDateFormat format = new SimpleDateFormat("EEEE"); |
| 1630 | + return format.format(date); |
| 1631 | + } |
| 1632 | + |
| 1633 | + /** |
| 1634 | + * Returns the day of the week for a given {@link LocalDate} object. |
| 1635 | + * |
| 1636 | + * @param date The {@link LocalDate} object. |
| 1637 | + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). |
| 1638 | + */ |
| 1639 | + public static String getDayOfWeekStr(LocalDate date) { |
| 1640 | + if (date == null) { |
| 1641 | + return ""; |
| 1642 | + } |
| 1643 | + return getDayOfWeek(date).getDisplayName(TextStyle.FULL, Locale.ENGLISH); |
| 1644 | + } |
| 1645 | + |
| 1646 | + /** |
| 1647 | + * Returns the day of the week for a given {@link LocalDateTime} object. |
| 1648 | + * |
| 1649 | + * @param date The {@link LocalDateTime} object. |
| 1650 | + * @return The full name of the day of the week (e.g., "Monday", "Tuesday"). |
| 1651 | + */ |
| 1652 | + public static String getDayOfWeek(LocalDateTime date) { |
| 1653 | + if (date == null) { |
| 1654 | + return ""; |
| 1655 | + } |
| 1656 | + return date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH); |
| 1657 | + } |
1603 | 1658 | }
|
0 commit comments