Java Code Examples for java.time.LocalDate#getMonthValue()
The following examples show how to use
java.time.LocalDate#getMonthValue() .
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: ColumnTest.java From tablesaw with Apache License 2.0 | 6 votes |
private static String getSeason(LocalDate date) { String season = ""; int month = date.getMonthValue(); int day = date.getDayOfMonth(); if (month == 1 || month == 2 || (month == 3 && day <= 15) || (month == 12 && day >= 16)) season = "WINTER"; else if (month == 4 || month == 5 || (month == 3 && day >= 16) || (month == 6 && day <= 15)) season = "SPRING"; else if (month == 7 || month == 8 || (month == 6 && day >= 16) || (month == 9 && day <= 15)) season = "SUMMER"; else if (month == 10 || month == 11 || (month == 9 && day >= 16) || (month == 12 && day <= 15)) season = "FALL"; return season; }
Example 2
Source File: TCKWeekFields.java From hottub with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="weekFields") public void test_parse_resolve_localizedWom(DayOfWeek firstDayOfWeek, int minDays) { LocalDate date = LocalDate.of(2012, 12, 15); WeekFields week = WeekFields.of(firstDayOfWeek, minDays); TemporalField womField = week.weekOfMonth(); for (int i = 1; i <= 60; i++) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(MONTH_OF_YEAR).appendLiteral(':') .appendValue(womField).appendLiteral(':') .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(SMART); String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(womField) + ":" + date.get(DAY_OF_WEEK); LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, date, " ::" + str + "::" + i); date = date.plusDays(1); } }
Example 3
Source File: TCKWeekFields.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="weekFields") public void test_parse_resolve_localizedWoyDow(DayOfWeek firstDayOfWeek, int minDays) { LocalDate date = LocalDate.of(2012, 12, 15); WeekFields week = WeekFields.of(firstDayOfWeek, minDays); TemporalField dowField = week.dayOfWeek(); TemporalField woyField = week.weekOfYear(); for (int i = 1; i <= 60; i++) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(MONTH_OF_YEAR).appendLiteral(':') .appendValue(woyField).appendLiteral(':') .appendValue(dowField).toFormatter(); String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(woyField) + ":" + date.get(dowField); LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, date, " :: " + str + " " + i); date = date.plusDays(1); } }
Example 4
Source File: SumkDate.java From sumk with Apache License 2.0 | 6 votes |
/** * @param date * 可以为null,如果为null,年份就是1970-01-01 * @param time * 可以为null * @return SumkDate对象 */ public static SumkDate of(LocalDate date, LocalTime time) { int year, month, day; if (date != null) { year = date.getYear(); month = date.getMonthValue(); day = date.getDayOfMonth(); } else { year = 1970; month = 1; day = 1; } if (time != null) { return of(year, month, day, time.getHour(), time.getMinute(), time.getSecond(), time.get(ChronoField.MILLI_OF_SECOND)); } return new SumkDate(year, (byte) month, (byte) day, (byte) 0, (byte) 0, (byte) 0, (byte) 0); }
Example 5
Source File: TCKWeekFields.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="weekFields") public void test_parse_resolve_localizedWomDow(DayOfWeek firstDayOfWeek, int minDays) { LocalDate date = LocalDate.of(2012, 12, 15); WeekFields week = WeekFields.of(firstDayOfWeek, minDays); TemporalField dowField = week.dayOfWeek(); TemporalField womField = week.weekOfMonth(); for (int i = 1; i <= 15; i++) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(MONTH_OF_YEAR).appendLiteral(':') .appendValue(womField).appendLiteral(':') .appendValue(dowField).toFormatter(); String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(womField) + ":" + date.get(dowField); LocalDate parsed = LocalDate.parse(str, f); assertEquals(parsed, date, " :: " + str + " " + i); date = date.plusDays(1); } }
Example 6
Source File: TCKWeekFields.java From j2objc with Apache License 2.0 | 6 votes |
@Test @UseDataProvider("data_weekFields") public void test_parse_resolve_localizedWoyDow(DayOfWeek firstDayOfWeek, int minDays) { LocalDate date = LocalDate.of(2012, 12, 15); WeekFields week = WeekFields.of(firstDayOfWeek, minDays); TemporalField dowField = week.dayOfWeek(); TemporalField woyField = week.weekOfYear(); for (int i = 1; i <= 60; i++) { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral(':') .appendValue(MONTH_OF_YEAR).appendLiteral(':') .appendValue(woyField).appendLiteral(':') .appendValue(dowField).toFormatter(); String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(woyField) + ":" + date.get(dowField); LocalDate parsed = LocalDate.parse(str, f); assertEquals(" :: " + str + " " + i, parsed, date); date = date.plusDays(1); } }
Example 7
Source File: TCKLocalizedPrinterParser.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") @Test(dataProvider="date") public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) { DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale); Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth()); String text = old.format(oldDate); DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale); TemporalAccessor parsed = f.parse(text, pos); assertEquals(pos.getIndex(), text.length()); assertEquals(pos.getErrorIndex(), -1); assertEquals(LocalDate.from(parsed), date); }
Example 8
Source File: LocationInfo.java From Weather-Forecast with Apache License 2.0 | 5 votes |
private static DateObjects GetLocalDate() { final Date date = new Date(); final LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); final int year = localDate.getYear(); final int month = localDate.getMonthValue(); final int day = localDate.getDayOfMonth(); return new DateObjects(year, month, day); }
Example 9
Source File: LocalDateComparator.java From flink with Apache License 2.0 | 5 votes |
public static void putNormalizedKeyLocalDate(LocalDate record, MemorySegment target, int offset, int numBytes) { int year = record.getYear(); int unsignedYear = year - Integer.MIN_VALUE; if (numBytes >= 4) { target.putIntBigEndian(offset, unsignedYear); numBytes -= 4; offset += 4; } else if (numBytes > 0) { for (int i = 0; numBytes > 0; numBytes--, i++) { target.put(offset + i, (byte) (unsignedYear >>> ((3 - i) << 3))); } return; } int month = record.getMonthValue(); if (numBytes > 0) { target.put(offset, (byte) (month & 0xff - Byte.MIN_VALUE)); numBytes -= 1; offset += 1; } int day = record.getDayOfMonth(); if (numBytes > 0) { target.put(offset, (byte) (day & 0xff - Byte.MIN_VALUE)); numBytes -= 1; offset += 1; } for (int i = 0; i < numBytes; i++) { target.put(offset + i, (byte) 0); } }
Example 10
Source File: LunarDate.java From jstarcraft-core with Apache License 2.0 | 5 votes |
/** * 通过标准日期获取阴历日期 * * @param date */ public LunarDate(LocalDate date) { int year = date.getYear(); int month = date.getMonthValue(); int day = date.getDayOfMonth(); int[] values = lunar2Solar[year - MINIMUM_YEAR]; int index = binarySearch(values, 0, values.length, month * 100 + day) - 1; if (index == 0) { year = year - 1; month = month + 12; values = lunar2Solar[year - MINIMUM_YEAR]; index = binarySearch(values, 0, values.length, month * 100 + day) - 1; } // 最接近的农历月份 int value = values[index]; LocalDate from = new SolarDate(year, value / 100, value % 100).getDate(); LocalDate to = date; this.year = year; int leap = values[0]; if (leap > 0) { this.leap = leap + 1 == index; if (index > leap) { this.month = index - 1; } else { this.month = index; } } else { this.leap = false; this.month = index; } this.day = (int) ChronoUnit.DAYS.between(from, to) + 1; }
Example 11
Source File: TCKLocalizedPrinterParser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") @Test(dataProvider="date") public void test_date_print(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) { DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale); Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth()); String text = old.format(oldDate); DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale); String formatted = f.format(date); assertEquals(formatted, text); }
Example 12
Source File: DateAdjusters.java From Strata with Apache License 2.0 | 5 votes |
/** * Finds the next leap day after the input date. * * @param input the input date * @return the next leap day date */ static LocalDate nextLeapDay(LocalDate input) { // already a leap day, move forward either 4 or 8 years if (input.getMonthValue() == 2 && input.getDayOfMonth() == 29) { return ensureLeapDay(input.getYear() + 4); } // handle if before February 29 in a leap year if (input.isLeapYear() && input.getMonthValue() <= 2) { return LocalDate.of(input.getYear(), 2, 29); } // handle any other date return ensureLeapDay(((input.getYear() / 4) * 4) + 4); }
Example 13
Source File: ImmutableHolidayCalendar.java From Strata with Apache License 2.0 | 5 votes |
@Override public int daysBetween(LocalDate startInclusive, LocalDate endExclusive) { ArgChecker.inOrderOrEqual(startInclusive, endExclusive, "startInclusive", "endExclusive"); try { // find data for start and end month int startIndex = (startInclusive.getYear() - startYear) * 12 + startInclusive.getMonthValue() - 1; int endIndex = (endExclusive.getYear() - startYear) * 12 + endExclusive.getMonthValue() - 1; // count of first month = ones after day of month inclusive // e.g 4th day of month - want holidays from index 3 inclusive int start = Integer.bitCount(lookup[startIndex] >>> (startInclusive.getDayOfMonth() - 1)); // count of last month = ones before day of month exclusive == total for month - ones after end inclusive int missingEnd = Integer.bitCount(lookup[endIndex] >>> (endExclusive.getDayOfMonth() - 1)); if (startIndex == endIndex) { // same month - return holidays up to end exclusive return start - missingEnd; } int end = Integer.bitCount(lookup[endIndex]) - missingEnd; // otherwise add start and end month counts, and sum months between int count = start + end; for (int i = startIndex + 1; i < endIndex; i++) { count += Integer.bitCount(lookup[i]); } return count; } catch (ArrayIndexOutOfBoundsException ex) { return daysBetweenOutOfRange(startInclusive, endExclusive); } }
Example 14
Source File: JavatimeTest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private static boolean isEqual(LocalDate ld, java.sql.Date d) { return ld.getYear() == d.getYear() + 1900 && ld.getMonthValue() == d.getMonth() + 1 && ld.getDayOfMonth() == d.getDate(); }
Example 15
Source File: JavatimeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static boolean isEqual(LocalDate ld, java.sql.Date d) { return ld.getYear() == d.getYear() + 1900 && ld.getMonthValue() == d.getMonth() + 1 && ld.getDayOfMonth() == d.getDate(); }
Example 16
Source File: PolicyGenerator.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
private String policyNumber(int i,LocalDate salesDate, String agent, String product) { return salesDate.getYear() + "/" + salesDate.getMonthValue() + "/" + salesDate.getDayOfMonth() + "/" + products.indexOf(product) + "/" + agents.indexOf(agent) + "/" + i; }
Example 17
Source File: JavatimeTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private static boolean isEqual(LocalDate ld, java.sql.Date d) { return ld.getYear() == d.getYear() + 1900 && ld.getMonthValue() == d.getMonth() + 1 && ld.getDayOfMonth() == d.getDate(); }
Example 18
Source File: PartitionByMonthAndHistory.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
private int getEndPartition(String endValueText, LocalDate beginDate) { TemporalAccessor date = formatter.parse(endValueText); return ((date.get(ChronoField.YEAR) - beginDate.getYear()) * 12 + date.get(ChronoField.MONTH_OF_YEAR) - beginDate.getMonthValue()); }
Example 19
Source File: CdsImmDateLogic.java From Strata with Apache License 2.0 | 3 votes |
/** * Checks if the given date is one of the semi-annual roll dates. * <p> * The semi-annual roll dates are 20th March and September. * * @param date the date * @return true is date is a roll date, false otherwise */ static boolean isSemiAnnualRollDate(LocalDate date) { if (date.getDayOfMonth() != IMM_DAY) { return false; } int month = date.getMonthValue(); return month == INDEX_ROLL_MONTHS.get(0) || month == INDEX_ROLL_MONTHS.get(1); }
Example 20
Source File: Date.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Obtains an instance of {@code Date} from a {@link LocalDate} object * with the same year, month and day of month value as the given * {@code LocalDate}. * <p> * The provided {@code LocalDate} is interpreted as the local date * in the local time zone. * * @param date a {@code LocalDate} to convert * @return a {@code Date} object * @exception NullPointerException if {@code date} is null * @since 1.8 */ @SuppressWarnings("deprecation") public static Date valueOf(LocalDate date) { return new Date(date.getYear() - 1900, date.getMonthValue() -1, date.getDayOfMonth()); }