java.time.YearMonth.atDay()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中java.time.YearMonth.atDay()方法的一些代码示例,展示了YearMonth.atDay()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.atDay()方法的具体详情如下:
包路径:java.time.YearMonth
类名称:YearMonth
方法名:atDay

YearMonth.atDay介绍

[英]Combines this year-month with a day-of-month to create a LocalDate.

This returns a LocalDate formed from this year-month and the specified day-of-month.

The day-of-month value must be valid for the year-month.

This method can be used as part of a chain to produce a date:

  1. LocalDate date = year.atMonth(month).atDay(day);

[中]将今年的月份与月份中的某一天合并以创建LocalDate。
这将返回从今年月份和指定的月份日期形成的LocalDate。
“月日”值必须对该年的月份有效。
此方法可作为链的一部分用于生成日期:

  1. LocalDate date = year.atMonth(month).atDay(day);

代码示例

代码示例来源:origin: jfoenixadmin/JFoenix

  1. private String formatMonth(YearMonth yearMonth) {
  2. try {
  3. Chronology chrono = getPrimaryChronology();
  4. ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1));
  5. return monthFormatter.withLocale(getLocale()).withChronology(chrono).format(cDate);
  6. } catch (DateTimeException ex) {
  7. // Date is out of range.
  8. return "";
  9. }
  10. }

代码示例来源:origin: jfoenixadmin/JFoenix

  1. void updateWeekNumberDateCells() {
  2. if (datePicker.isShowWeekNumbers()) {
  3. final Locale locale = getLocale();
  4. LocalDate firstDayOfMonth = selectedYearMonth.get().atDay(1);
  5. for (int i = 0; i < 6; i++) {
  6. LocalDate date = firstDayOfMonth.plus(i, WEEKS);
  7. String weekNumber = weekNumberFormatter.withLocale(locale)
  8. .withDecimalStyle(DecimalStyle.of(locale))
  9. .format(date);
  10. weekNumberCells.get(i).setText(weekNumber);
  11. }
  12. }
  13. }

代码示例来源:origin: jfoenixadmin/JFoenix

  1. protected void updateMonthYearPane() {
  2. // update date labels
  3. YearMonth yearMonth = selectedYearMonth.get();
  4. LocalDate value = datePicker.getValue();
  5. value = value == null ? LocalDate.now() : value;
  6. selectedDateLabel.setText(DateTimeFormatter.ofPattern("EEE, MMM dd").format(value));
  7. selectedYearLabel.setText(formatYear(yearMonth));
  8. monthYearLabel.setText(formatMonth(yearMonth) + " " + formatYear(yearMonth));
  9. Chronology chrono = datePicker.getChronology();
  10. LocalDate firstDayOfMonth = yearMonth.atDay(1);
  11. backMonthButton.setDisable(!isValidDate(chrono, firstDayOfMonth, -1, DAYS));
  12. forwardMonthButton.setDisable(!isValidDate(chrono, firstDayOfMonth, +1, MONTHS));
  13. }

代码示例来源:origin: jfoenixadmin/JFoenix

  1. private String formatYear(YearMonth yearMonth) {
  2. try {
  3. Chronology chrono = getPrimaryChronology();
  4. ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1));
  5. return yearFormatter.withLocale(getLocale())
  6. .withChronology(chrono)
  7. .withDecimalStyle(DecimalStyle.of(getLocale()))
  8. .format(cDate);
  9. } catch (DateTimeException ex) {
  10. // Date is out of range.
  11. return "";
  12. }
  13. }

代码示例来源:origin: com.thoughtworks.xstream/xstream

  1. return GregorianCalendar.from(ym.atDay(1).atStartOfDay(ZoneId.systemDefault()));
  2. } catch (final DateTimeParseException e) {

代码示例来源:origin: jfoenixadmin/JFoenix

  1. int firstOfMonthIndex = selectedYearMonth.get().atDay(1).getDayOfWeek().getValue() - firstDayOfWeek;
  2. firstOfMonthIndex += firstOfMonthIndex < 0 ? daysPerWeek : 0;
  3. YearMonth currentYearMonth = selectedYearMonth.get();
  4. LocalDate date = currentYearMonth.atDay(dayIndex);
  5. dayCellDates[i] = date;

代码示例来源:origin: jfoenixadmin/JFoenix

  1. DateCell dateCell = currentFocusedDayCell;
  2. if (dateCell == null || !(dayCellDate(dateCell).getMonth() == yearMonth.getMonth())) {
  3. dateCell = findDayCellOfDate(yearMonth.atDay(1));

代码示例来源:origin: stackoverflow.com

  1. // From Date to YearMonth
  2. YearMonth yearMonth =
  3. YearMonth.from(date.toInstant()
  4. .atZone(ZoneId.systemDefault())
  5. .toLocalDate());
  6. // From YearMonth to Date
  7. // The same as the OP:s answer
  8. final Date convertedFromYearMonth =
  9. Date.from(yearMonth.atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant());

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

  1. /**
  2. * Returns a {@link java.time.LocalDate} of this year/month and the given day of the month.
  3. *
  4. * @param self a YearMonth
  5. * @param dayOfMonth a day of the month
  6. * @return a LocalDate
  7. * @since 2.5.0
  8. */
  9. public static LocalDate leftShift(final YearMonth self, int dayOfMonth) {
  10. return self.atDay(dayOfMonth);
  11. }

代码示例来源:origin: org.codehaus.groovy/groovy-datetime

  1. /**
  2. * Returns a {@link java.time.Period} of time between the first day of this year/month (inclusive) and the
  3. * given {@link java.time.YearMonth} (exclusive).
  4. *
  5. * @param self a YearMonth
  6. * @param other another YearMonth
  7. * @return a Period
  8. * @since 2.5.0
  9. */
  10. public static Period rightShift(YearMonth self, YearMonth other) {
  11. return Period.between(self.atDay(1), other.atDay(1));
  12. }

代码示例来源:origin: stackoverflow.com

  1. // Code for your method.
  2. YearMonth yearMonth = year.atMonth ( month ); // Instantiate a YearMonth from a Year and a Month.
  3. LocalDate localDate = yearMonth.atDay ( 1 ); // First day of month.
  4. ZoneId zoneId = ZoneId.systemDefault (); // Or… ZoneId.of("America/Montreal");
  5. ZonedDateTime zdt = localDate.atStartOfDay ( zoneId );
  6. long millis = zdt.toInstant ().toEpochMilli ();

代码示例来源:origin: arnaudroger/SimpleFlatMapper

  1. @Override
  2. public Date convert(YearMonth in, Context context) throws Exception {
  3. if (in == null) return null;
  4. return Date.from(in.atDay(1).atStartOfDay(zoneId).toInstant());
  5. }
  6. }

代码示例来源:origin: org.simpleflatmapper/sfm-converter

  1. @Override
  2. public Date convert(YearMonth in, Context context) throws Exception {
  3. if (in == null) return null;
  4. return Date.from(in.atDay(1).atStartOfDay(zoneId).toInstant());
  5. }
  6. }

代码示例来源:origin: OpenGamma/Strata

  1. @Override
  2. public LocalDate dateMatching(YearMonth yearMonth) {
  3. return nextOrSame(yearMonth.atDay(1));
  4. }
  5. };

代码示例来源:origin: stackoverflow.com

  1. YearMonth yearMonthObject = YearMonth.of(year, month);
  2. int daysOfCurrentMonth = yearMonthObject.lengthOfMonth();
  3. ArrayList<LocalDate> dayes = new ArrayList<LocalDate>();
  4. for(int i = 1; i <= daysOfCurrentMonth; i++){
  5. dayes.add(yearMonthObject.atDay(i));
  6. }
  7. dayes.forEach(value -> System.out.println(value.getDayOfMonth() + " " + value.getDayOfWeek()));

代码示例来源:origin: OpenGamma/Strata

  1. @Override
  2. public LocalDate dateMatching(YearMonth yearMonth) {
  3. return nextOrSame(yearMonth.atDay(1));
  4. }
  5. },

代码示例来源:origin: stackoverflow.com

  1. ZonedId zoneId = ZoneId.of( "America/Montreal" );
  2. YearMonth yearMonthNow = YearMonth.now( zoneId );
  3. YearMonth yearMonthPrevious = yearMonthNow.minusMonths( 1 );
  4. LocalDate firstOfMonth = yearMonthPrevious.atDay( 1 );
  5. LocalDate lastOfMonth = yearMonthPrevious.atEndOfMonth();

代码示例来源:origin: com.github.robozonky/robozonky-api

  1. public static OffsetDateTime toOffsetDateTime(final String format, final String date) {
  2. switch (format) { // the only two formats, as confirmed via e-mail with Zonky employees
  3. case "yyyy-MM":
  4. return YearMonth.parse(date, YEAR_MONTH)
  5. .atDay(1)
  6. .atStartOfDay(Defaults.ZONE_ID).toOffsetDateTime();
  7. case "yyyy-MM-dd'T'HH:mm:ssZ":
  8. return OffsetDateTime.parse(date, DateTimeFormatter.ISO_DATE_TIME);
  9. default:
  10. throw new IllegalArgumentException("Unknown date format ID: " + format);
  11. }
  12. }

代码示例来源:origin: kaif-open/kaif

  1. /**
  2. * create monthly ranking now
  3. */
  4. public static HonorRoll zero(UUID accountId, Zone zone, YearMonth yearMonth, String username) {
  5. return new HonorRoll(accountId, zone, yearMonth.atDay(1).toString(), username, 0, 0, 0);
  6. }

代码示例来源:origin: arnaudroger/SimpleFlatMapper

  1. @Test
  2. public void testJavaYearMonth() throws Exception {
  3. java.time.YearMonth value = java.time.YearMonth.now();
  4. java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
  5. newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.YearMonth>(value), java.time.YearMonth.class, new JavaZoneIdProperty(zoneId));
  6. newFieldMapperAndMapToPS(NullGetter.<Object, java.time.YearMonth>getter(), java.time.YearMonth.class);
  7. verify(ps).setDate(1, new java.sql.Date(value.atDay(1).atStartOfDay(zoneId).toInstant().toEpochMilli()));
  8. verify(ps).setNull(2, Types.DATE);
  9. }

相关文章