Java Code Examples for java.time.LocalDate#getMonth()
The following examples show how to use
java.time.LocalDate#getMonth() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestLocalDate.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private LocalDate next(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() + 1; if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) { return date.withDayOfMonth(newDayOfMonth); } date = date.withDayOfMonth(1); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() + 1); } return date.with(date.getMonth().plus(1)); }
Example 2
Source File: TCKLocalDate.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 3
Source File: DateUtils.java From Raincat with GNU Lesser General Public License v3.0 | 5 votes |
/** * 判断当前期为每几个季度. * * @param date 日期 * @return 1 第一季度 2 第二季度 3 第三季度 4 第四季度 */ public static int getSeason(final LocalDate date) { int season = 0; Month month = date.getMonth(); switch (month) { case JANUARY: case FEBRUARY: case MARCH: season = 1; break; case APRIL: case MAY: case JUNE: season = 2; break; case JULY: case AUGUST: case SEPTEMBER: season = 3; break; case OCTOBER: case NOVEMBER: case DECEMBER: season = 4; break; default: break; } return season; }
Example 4
Source File: TCKLocalDate.java From hottub with GNU General Public License v2.0 | 5 votes |
private LocalDate next(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() + 1; if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) { return date.withDayOfMonth(newDayOfMonth); } date = date.withDayOfMonth(1); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() + 1); } return date.with(date.getMonth().plus(1)); }
Example 5
Source File: TCKLocalDate.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 6
Source File: TestLocalDate.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 7
Source File: TestLocalDate.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private LocalDate next(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() + 1; if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) { return date.withDayOfMonth(newDayOfMonth); } date = date.withDayOfMonth(1); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() + 1); } return date.with(date.getMonth().plus(1)); }
Example 8
Source File: TestLocalDate.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 9
Source File: TestLocalDate.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 10
Source File: TCKLocalDate.java From j2objc with Apache License 2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 11
Source File: TCKLocalDate.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 12
Source File: TestLocalDate.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 13
Source File: TestLocalDate.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 14
Source File: TestLocalDate.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private LocalDate next(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() + 1; if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) { return date.withDayOfMonth(newDayOfMonth); } date = date.withDayOfMonth(1); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() + 1); } return date.with(date.getMonth().plus(1)); }
Example 15
Source File: TCKLocalDate.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private LocalDate next(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() + 1; if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) { return date.withDayOfMonth(newDayOfMonth); } date = date.withDayOfMonth(1); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() + 1); } return date.with(date.getMonth().plus(1)); }
Example 16
Source File: TestLocalDate.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 17
Source File: TCKLocalDate.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
Example 18
Source File: LocalDatePeriodCountCalculator.java From objectlabkit with Apache License 2.0 | 5 votes |
private int diff360EIsda(final LocalDate start, final LocalDate end) { if (start.equals(end)) { return 0; } int dayStart = start.getDayOfMonth(); int dayEnd = end.getDayOfMonth(); if (start.getMonth().length(start.isLeapYear()) == dayStart) { dayStart = CalculatorConstants.MONTH_30_DAYS; } if (end.getMonth() != Month.FEBRUARY && end.getMonth().length(end.isLeapYear()) == dayEnd) { dayEnd = CalculatorConstants.MONTH_30_DAYS; } return (end.getYear() - start.getYear()) * CalculatorConstants.YEAR_360 + (end.getMonthValue() - start.getMonthValue()) * CalculatorConstants.MONTH_30_DAYS + dayEnd - dayStart; }
Example 19
Source File: TCKLocalDate.java From j2objc with Apache License 2.0 | 5 votes |
private LocalDate next(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() + 1; if (newDayOfMonth <= date.getMonth().length(isIsoLeap(date.getYear()))) { return date.withDayOfMonth(newDayOfMonth); } date = date.withDayOfMonth(1); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() + 1); } return date.with(date.getMonth().plus(1)); }
Example 20
Source File: DateTimeExamples.java From Java8InAction with MIT License | 4 votes |
private static void useLocalDate() { LocalDate date = LocalDate.of(2014, 3, 18); int year = date.getYear(); // 2014 Month month = date.getMonth(); // MARCH int day = date.getDayOfMonth(); // 18 DayOfWeek dow = date.getDayOfWeek(); // TUESDAY int len = date.lengthOfMonth(); // 31 (days in March) boolean leap = date.isLeapYear(); // false (not a leap year) System.out.println(date); int y = date.get(ChronoField.YEAR); int m = date.get(ChronoField.MONTH_OF_YEAR); int d = date.get(ChronoField.DAY_OF_MONTH); LocalTime time = LocalTime.of(13, 45, 20); // 13:45:20 int hour = time.getHour(); // 13 int minute = time.getMinute(); // 45 int second = time.getSecond(); // 20 System.out.println(time); LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); // 2014-03-18T13:45 LocalDateTime dt2 = LocalDateTime.of(date, time); LocalDateTime dt3 = date.atTime(13, 45, 20); LocalDateTime dt4 = date.atTime(time); LocalDateTime dt5 = time.atDate(date); System.out.println(dt1); LocalDate date1 = dt1.toLocalDate(); System.out.println(date1); LocalTime time1 = dt1.toLocalTime(); System.out.println(time1); Instant instant = Instant.ofEpochSecond(44 * 365 * 86400); Instant now = Instant.now(); Duration d1 = Duration.between(LocalTime.of(13, 45, 10), time); Duration d2 = Duration.between(instant, now); System.out.println(d1.getSeconds()); System.out.println(d2.getSeconds()); Duration threeMinutes = Duration.of(3, ChronoUnit.MINUTES); System.out.println(threeMinutes); JapaneseDate japaneseDate = JapaneseDate.from(date); System.out.println(japaneseDate); }