gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-17 23:46:40 32 4
gpt4 key购买 nike

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

YearMonth.lengthOfMonth介绍

[英]Returns the length of the month, taking account of the year.

This returns the length of the month in days. For example, a date in January would return 31.
[中]返回月份的长度,考虑年份。
这将以天为单位返回月份的长度。例如,1月份的日期将返回31。

代码示例

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

daysInCurMonth = currentYearMonth.lengthOfMonth();

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Checks if the day-of-month is valid for this year-month.
 * <p>
 * This method checks whether this year and month and the input day form
 * a valid date.
 *
 * @param dayOfMonth  the day-of-month to validate, from 1 to 31, invalid value returns false
 * @return true if the day is valid for this year-month
 */
public boolean isValidDay(int dayOfMonth) {
  return dayOfMonth >= 1 && dayOfMonth <= lengthOfMonth();
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
 * Returns a {@code LocalDate} at the end of the month.
 * <p>
 * This returns a {@code LocalDate} based on this year-month.
 * The day-of-month is set to the last valid day of the month, taking
 * into account leap years.
 * <p>
 * This method can be used as part of a chain to produce a date:
 * <pre>
 *  LocalDate date = year.atMonth(month).atEndOfMonth();
 * </pre>
 *
 * @return the last valid date of this year-month, not null
 */
public LocalDate atEndOfMonth() {
  return LocalDate.of(year, month, lengthOfMonth());
}

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

YearMonth yearMonthObject = YearMonth.of(year, month);
int daysOfCurrentMonth = yearMonthObject.lengthOfMonth();

ArrayList<LocalDate> dayes = new ArrayList<LocalDate>();
for(int i = 1; i <= daysOfCurrentMonth; i++){
  dayes.add(yearMonthObject.atDay(i));
}

dayes.forEach(value -> System.out.println(value.getDayOfMonth() + " " + value.getDayOfWeek()));

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

YearMonth ym = YearMonth.of( 2016 , Month.JANUARY ) ;
int initialCapacity = ( ( ym.lengthOfMonth() / 7 ) + 1 ) * dows.size() ;  // Maximum possible weeks * number of days per week.
List<LocalDate> dates = new ArrayList<>(  initialCapacity  );
for (int dayOfMonth = 1;  dayOfMonth <= ym.lengthOfMonth() ;  dayOfMonth ++) {
  LocalDate ld =  ym.atDay( dayOfMonth ) ;
  DayOfWeek dow = ld.getDayOfWeek() ;
  if( dows.contains( dow ) ) {  
    // Is this date *is* one of the days we care about, collect it.
    dates.add( ld );
  }
}

代码示例来源:origin: AnalyticalGraphicsInc/czml-writer

/**
 * Returns the number of days in the specified month and year.
 *
 * @param year
 *            The year
 * @param month
 *            The month (from 1 to 12)
 */
public static int daysInMonth(int year, int month) {
  return YearMonth.of(year, month).lengthOfMonth();
}

代码示例来源:origin: org.threeten/threeten-extra

/**
 * Combines this day-of-month with a year-month to create a {@code LocalDate}.
 * <p>
 * This returns a {@code LocalDate} formed from this year and the specified year-month.
 * <p>
 * If this day-of-month is invalid for the year-month then it will be changed
 * to the last valid date for the month.
 *
 * @param yearMonth  the year-month to use, not null
 * @return the local date formed from this year and the specified year-month, not null
 */
public LocalDate atYearMonth(YearMonth yearMonth) {
  return yearMonth.atDay(Math.min(day, yearMonth.lengthOfMonth()));
}

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

import java.time.DayOfWeek;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.util.stream.IntStream;

class Stackoverflow{
  public static void main(String args[]){

    int year    = 2010;
    Month month = Month.JANUARY;

    IntStream.rangeClosed(1,YearMonth.of(year, month).lengthOfMonth())
         .mapToObj(day -> LocalDate.of(year, month, day))
         .filter(date -> date.getDayOfWeek() == DayOfWeek.SATURDAY ||
                 date.getDayOfWeek() == DayOfWeek.SUNDAY)
         .forEach(date -> System.out.print(date.getDayOfMonth() + " "));
  }
}

代码示例来源:origin: org.tiogasolutions.dev/tioga-dev-common

public LocalDate toLastDate(LocalDate date) {
 YearMonth yearMonth = toYearMonth(date);
 int lastDayOfMonth = yearMonth.lengthOfMonth();
 return (date == null) ? null : LocalDate.of(date.getYear(), date.getMonthValue(), lastDayOfMonth);
}
public LocalDateTime toLastDate(LocalDateTime date) {

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

YearMonth ym = ymStart;
do {
  int daysInMonth = ym.lengthOfMonth ();
  String monthName = ym.getMonth ().getDisplayName ( TextStyle.FULL , Locale.CANADA_FRENCH );

  System.out.println ( ym + " : " + daysInMonth + " jours en " + monthName );

  // Prepare for next loop.
  ym = ym.plusMonths ( 1 );
} while ( ym.isBefore ( ymStop ) );

代码示例来源:origin: tmobile/pacbot

public List<LocalDate> getListOfLastWeekDateOfQuarter() {
  LocalDate today = LocalDate.now();
  LocalDate startDate = LocalDate.of(today.getYear(), today.getMonth().firstMonthOfQuarter(), 1);
  Month firstMonthOftheQuarter = startDate.getMonth();
  Month secMonthOftheQuarter = startDate.getMonth().plus(1);
  Month thirdMonthOftheQuarter = secMonthOftheQuarter.plus(1);
  List<Month> monthList = new ArrayList<>();
  monthList.add(firstMonthOftheQuarter);
  monthList.add(secMonthOftheQuarter);
  monthList.add(thirdMonthOftheQuarter);
  int year = today.getYear();
  List<LocalDate> lastWeeksOfQuarterList = new ArrayList<>();
  for (Month month : monthList) {
    IntStream.rangeClosed(1, YearMonth.of(year, month).lengthOfMonth())
        .mapToObj(day -> LocalDate.of(year, month, day))
        .filter(date -> date.getDayOfWeek() == DayOfWeek.SUNDAY)
        .forEach(date -> lastWeeksOfQuarterList.add(date));
  }
  return lastWeeksOfQuarterList;
}

代码示例来源:origin: de.adorsys.smartanalytics/smartanalytics-classification

int lastDayInMonth = YearMonth.from(nextMonth).lengthOfMonth();
if (lastDayInMonth < nextBookingDay) {
  nextBookingDay = lastDayInMonth;

代码示例来源:origin: org.tiogasolutions.dev/tioga-dev-common

public LocalDateTime toLastDate(LocalDateTime date) {
 YearMonth yearMonth = toYearMonth(date);
 int lastDayOfMonth = yearMonth.lengthOfMonth();
 return (date == null) ? null : LocalDateTime.of(date.getYear(), date.getMonthValue(), lastDayOfMonth,
                         date.getHour(), date.getMinute(), date.getSecond(), date.getNano());
}
public ZonedDateTime toLastDate(ZonedDateTime date) {

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

YearMonth yearMonth = startYm;
do {
  int days = 0;
  if ( startYm.equals ( stopYm ) ) { // If within the same (single) month.
    days = ( int ) ChronoUnit.DAYS.between ( start , stop );
  } else if ( yearMonth.equals ( startYm ) ) { // If on the first month of multiple months, count days.
    days = ( int ) ChronoUnit.DAYS.between ( start , startYm.plusMonths ( 1 ).atDay ( 1 ) ); //  Get first of next month, to accommodate the `between` method’s use of Half-Open logic.
  } else if ( yearMonth.isAfter ( startYm ) && yearMonth.isBefore ( stopYm ) ) { // If on the in-between months, ask for the days of that month.
    days = yearMonth.lengthOfMonth ();
  } else if ( yearMonth.equals ( stopYm ) ) {  // If on the last of multiple months.
    days = ( int ) ChronoUnit.DAYS.between ( stopYm.atDay ( 1 ).minusDays ( 1 ) , stop ); // Get last day of previous month, to accommodate the `between` method’s use of Half-Open logic.
  } else {
    System.out.println ( "ERROR - Reached impossible point." );
    // FIXME: Handle error condition.
  }
  map.put ( yearMonth , days ); // Cast long to int, auto-boxed to Integer.
  // Prep for next loop.
  yearMonth = yearMonth.plusMonths ( 1 );
} while (  ! yearMonth.isAfter ( stopYm ) );

代码示例来源:origin: org.tiogasolutions.dev/tioga-dev-common

public ZonedDateTime toLastDate(ZonedDateTime date) {
 YearMonth yearMonth = toYearMonth(date);
 int lastDayOfMonth = yearMonth.lengthOfMonth();
 return (date == null) ? null : ZonedDateTime.of(date.getYear(), date.getMonthValue(), lastDayOfMonth,
                         date.getHour(), date.getMinute(), date.getSecond(), date.getNano(), date.getZone());
}

代码示例来源:origin: frode-carlsen/cron

boolean matches(LocalDate dato) {
  for (FieldPart part : parts) {
    if ("L".equals(part.modifier)) {
      YearMonth ym = YearMonth.of(dato.getYear(), dato.getMonth().getValue());
      return dato.getDayOfWeek() == DayOfWeek.of(part.from) && dato.getDayOfMonth() > (ym.lengthOfMonth() - 7);
    } else if ("#".equals(part.incrementModifier)) {
      if (dato.getDayOfWeek() == DayOfWeek.of(part.from)) {
        int num = dato.getDayOfMonth() / 7;
        return part.increment == (dato.getDayOfMonth() % 7 == 0 ? num : num + 1);
      }
      return false;
    } else if (matches(dato.getDayOfWeek().getValue(), part)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: io.micronaut/runtime

/**
 * Check if the date matches the day of the week.
 *
 * @param date The date
 * @return Whether the date matches the day of the field
 */
boolean matches(LocalDate date) {
  for (FieldPart part : parts) {
    if ("L".equals(part.modifier)) {
      YearMonth ym = YearMonth.of(date.getYear(), date.getMonth().getValue());
      return date.getDayOfWeek() == DayOfWeek.of(part.from) && date.getDayOfMonth() > (ym.lengthOfMonth() - DAYS_IN_WEEK);
    } else if ("#".equals(part.incrementModifier)) {
      if (date.getDayOfWeek() == DayOfWeek.of(part.from)) {
        int num = date.getDayOfMonth() / DAYS_IN_WEEK;
        return part.increment == (date.getDayOfMonth() % DAYS_IN_WEEK == 0 ? num : num + 1);
      }
      return false;
    } else if (matches(date.getDayOfWeek().getValue(), part)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: frode-carlsen/cron

boolean matches(LocalDate dato) {
  for (FieldPart part : parts) {
    if ("L".equals(part.modifier)) {
      YearMonth ym = YearMonth.of(dato.getYear(), dato.getMonth().getValue());
      return dato.getDayOfMonth() == (ym.lengthOfMonth() - (part.from == null ? 0 : part.from));
    } else if ("W".equals(part.modifier)) {
      if (dato.getDayOfWeek().getValue() <= 5) {
        if (dato.getDayOfMonth() == part.from) {
          return true;
        } else if (dato.getDayOfWeek().getValue() == 5) {
          return dato.plusDays(1).getDayOfMonth() == part.from;
        } else if (dato.getDayOfWeek().getValue() == 1) {
          return dato.minusDays(1).getDayOfMonth() == part.from;
        }
      }
    } else if (matches(dato.getDayOfMonth(), part)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: io.micronaut/runtime

/**
 * Check if the given date matches the day in the month.
 *
 * @param date The date
 * @return Whether the date matches the day in the month
 */
boolean matches(LocalDate date) {
  for (FieldPart part : parts) {
    if ("L".equals(part.modifier)) {
      YearMonth ym = YearMonth.of(date.getYear(), date.getMonth().getValue());
      return date.getDayOfMonth() == (ym.lengthOfMonth() - (part.from == null ? 0 : part.from));
    } else if ("W".equals(part.modifier)) {
      if (date.getDayOfWeek().getValue() <= WEEK_DAYS) {
        if (date.getDayOfMonth() == part.from) {
          return true;
        } else if (date.getDayOfWeek().getValue() == WEEK_DAYS) {
          return date.plusDays(ONE_DAY).getDayOfMonth() == part.from;
        } else if (date.getDayOfWeek().getValue() == FIRST_DAY) {
          return date.minusDays(ONE_DAY).getDayOfMonth() == part.from;
        }
      }
    } else if (matches(date.getDayOfMonth(), part)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: com.jfoenix/jfoenix

daysInCurMonth = currentYearMonth.lengthOfMonth();

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com