java.time.Period.ofDays()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(218)

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

Period.ofDays介绍

[英]Obtains a Period representing a number of days.

The resulting period will have the specified days. The years and months units will be zero.
[中]获取表示天数的期间。
结果期间将具有指定的天数。年和月单位将为零。

代码示例

代码示例来源:origin: floragunncom/search-guard

private static String addDays(String date, int days) {
  final LocalDate d = parseDate(date);
  return DEFAULT_FOMATTER.format(d.plus(Period.ofDays(days)));
}

代码示例来源:origin: biezhi/learn-java8

public static void main(String[] args) {
    // 创建一个ZonedDateTime实例
    ZonedDateTime dateTime = ZonedDateTime.now();

    // 使用指定的年月日、时分秒、纳秒以及时区ID来新建对象
    ZoneId        zoneId    = ZoneId.of("UTC+8");
    ZonedDateTime dateTime2 = ZonedDateTime.of(2018, 3, 8, 23, 45, 59, 1234, zoneId);

    // 3天后
    ZonedDateTime zoneDateTime = dateTime2.plus(Period.ofDays(3));

    ZoneId zoneId2 = ZoneId.of("Europe/Copenhagen");
    ZoneId zoneId3 = ZoneId.of("Europe/Paris");

    System.out.println("dateTime     : " + dateTime);
    System.out.println("zoneDateTime : " + zoneDateTime);
    System.out.println("zoneId2      : " + zoneId2);
    System.out.println("zoneId3      : " + zoneId3);
  }
}

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

/**
 * Gets the number of days as a {@code Period}.
 * <p>
 * This returns a period with the same number of days.
 *
 * @return the equivalent period, not null
 */
public Period toPeriod() {
  return Period.ofDays(days);
}

代码示例来源:origin: raphaelDL/spring-webflux-security-jwt

/**
   * Returns a millisecond time representation 24hrs from now
   * to be used as the time the currently token will be valid
   *
   * @return Time representation 24 from now
   */
  private static long getExpiration(){
    return new Date().toInstant()
        .plus(Period.ofDays(1))
        .toEpochMilli();
  }
}

代码示例来源:origin: ical4j/ical4j

public static TemporalAmountAdapter fromDateRange(Date start, Date end) {
  TemporalAmount duration;
  long durationMillis = end.getTime() - start.getTime();
  if (durationMillis % (24 * 60 * 60 * 1000) == 0) {
    duration = java.time.Period.ofDays((int) durationMillis / (24 * 60 * 60 * 1000));
  } else {
    duration = java.time.Duration.ofMillis(durationMillis);
  }
  return new TemporalAmountAdapter(duration);
}

代码示例来源:origin: zavtech/morpheus-core

/**
 * Returns a LocalDate range based on the start and end date
 * @param start the start of range, inclusive, expressed as yyyy-MM-dd
 * @param end   the end of range, exclusive, expressed as yyyy-MM-dd
 * @return      the newly created range
 */
static Range<LocalDate> ofLocalDates(String start, String end) {
  return Range.ofLocalDates(start, end, Period.ofDays(1));
}

代码示例来源:origin: zavtech/morpheus-core

/**
 * Returns a Range of LocalDate between the start and end specified with a step of 1-day
 * @param start the start of the range, inclusive
 * @param end   the end of the range, exclusive
 * @return      the newly created range
 */
static Range<LocalDate> of(LocalDate start, LocalDate end) {
  return new RangeOfLocalDates(start, end, Period.ofDays(1), null);
}

代码示例来源:origin: org.mnode.ical4j/ical4j

public static TemporalAmountAdapter fromDateRange(Date start, Date end) {
  TemporalAmount duration;
  long durationMillis = end.getTime() - start.getTime();
  if (durationMillis % (24 * 60 * 60 * 1000) == 0) {
    duration = java.time.Period.ofDays((int) durationMillis / (24 * 60 * 60 * 1000));
  } else {
    duration = java.time.Duration.ofMillis(durationMillis);
  }
  return new TemporalAmountAdapter(duration);
}

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

import java.time.*;

public class Test {
  public static void main(String[] args) {
    ZoneId zone = ZoneId.of("Europe/London");
    // At 2015-03-29T01:00:00Z, Europe/London goes from UTC+0 to UTC+1
    LocalDate transitionDate = LocalDate.of(2015, 3, 29);
    ZonedDateTime start = ZonedDateTime.of(transitionDate, LocalTime.MIDNIGHT, zone);
    ZonedDateTime endWithDuration = start.plus(Duration.ofDays(1));
    ZonedDateTime endWithPeriod = start.plus(Period.ofDays(1));
    System.out.println(endWithDuration); // 2015-03-30T01:00+01:00[Europe/London]
    System.out.println(endWithPeriod);   // 2015-03-30T00:00+01:00[Europe/London]
  }
}

代码示例来源:origin: jtransc/jtransc

static public void main(String[] args) {
    System.out.println("PeriodTest.main:");
    System.out.println(Period.ofDays(0).toString());
    System.out.println(Period.ofDays(1).toString());
    System.out.println(Period.ofDays(1).plusDays(40).toString());
    System.out.println(Period.parse(Period.ofDays(1).toString()));
  }
}

代码示例来源:origin: dremio/dremio-oss

/**
 * Create a schedule builder where events are triggered every {@code days}
 *
 * @param days the number of days between events
 * @return a schedule builder generating events every {@code days}
 * @throws IllegalArgumentException if {@code days} is negative
 */
public static Builder everyDays(int days) {
 return new Builder(Period.ofDays(checkInterval(days)));
}

代码示例来源:origin: dremio/dremio-oss

/**
 * Create a schedule builder where events are triggered every {@code days}, at a specific time
 *
 * @param days the number of days between events
 * @param at the specific time to generate the events at
 * @return a schedule builder generating events every {@code days}
 * @throws IllegalArgumentException if {@code days} is negative
 * @throws NullPointerException if {@code at} is null
 */
public static Builder everyDays(int days, LocalTime at) {
 Preconditions.checkNotNull(at);
 return everyDays(days).withAdjuster(sameOrNext(Period.ofDays(1), at));
}

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

public void test_parsePeriod() {
 assertEquals(LoaderUtils.parsePeriod("P2D"), Period.ofDays(2));
 assertEquals(LoaderUtils.parsePeriod("2D"), Period.ofDays(2));
 assertThrowsIllegalArg(() -> LoaderUtils.parsePeriod("2"));
}

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

public void test_getPeriod() {
 assertEquals(TENOR_3D.getPeriod(), Period.ofDays(3));
 assertEquals(TENOR_3W.getPeriod(), Period.ofDays(21));
 assertEquals(TENOR_3M.getPeriod(), Period.ofMonths(3));
 assertEquals(TENOR_3Y.getPeriod(), Period.ofYears(3));
}

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

public void hard_coded_value_one_curve_all_dates_tenor() {
 final LocalDate sensitivityDate = LocalDate.of(2015, 8, 18);
 Function<LocalDate, ParameterMetadata> parameterMetadataFunction =
   (d) -> TenorParameterMetadata.of(Tenor
     .of(Period.ofDays((int) (d.toEpochDay() - sensitivityDate.toEpochDay()))));
 Function<CurrencyParameterSensitivities, CurrencyParameterSensitivities> rebucketFunction =
   (s) -> CurveSensitivityUtils.linearRebucketing(s, TARGET_DATES, sensitivityDate);
 test_from_functions_one_curve_all_dates(parameterMetadataFunction, rebucketFunction);
}

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

public void hard_coded_value_one_curve_one_date_tenor() {
 final LocalDate sensitivityDate = LocalDate.of(2015, 8, 18);
 Function<LocalDate, ParameterMetadata> parameterMetadataFunction =
   (d) -> TenorParameterMetadata.of(Tenor
     .of(Period.ofDays((int) (d.toEpochDay() - sensitivityDate.toEpochDay()))));
 Function<CurrencyParameterSensitivities, CurrencyParameterSensitivities> rebucketFunction =
   (s) -> CurveSensitivityUtils.linearRebucketing(s, TARGET_DATES, sensitivityDate);
 test_from_functions_one_curve_one_date(parameterMetadataFunction, rebucketFunction);
}

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

public void test_of_notZero() {
 assertThrowsIllegalArg(() -> Tenor.of(Period.ofDays(0)));
 assertThrowsIllegalArg(() -> Tenor.ofDays(0));
 assertThrowsIllegalArg(() -> Tenor.ofWeeks(0));
 assertThrowsIllegalArg(() -> Tenor.ofMonths(0));
 assertThrowsIllegalArg(() -> Tenor.ofYears(0));
}

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

public void test_of_notZero() {
 assertThrowsIllegalArg(() -> Frequency.of(Period.ofDays(0)));
 assertThrowsIllegalArg(() -> Frequency.ofDays(0));
 assertThrowsIllegalArg(() -> Frequency.ofWeeks(0));
 assertThrowsIllegalArg(() -> Frequency.ofMonths(0));
 assertThrowsIllegalArg(() -> Frequency.ofYears(0));
}

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

public void test_of_notNegative() {
 assertThrowsIllegalArg(() -> Tenor.of(Period.ofDays(-1)));
 assertThrowsIllegalArg(() -> Tenor.ofDays(-1));
 assertThrowsIllegalArg(() -> Tenor.ofWeeks(-1));
 assertThrowsIllegalArg(() -> Tenor.ofMonths(-1));
 assertThrowsIllegalArg(() -> Tenor.ofYears(-1));
}

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

public void test_of_notNegative() {
 assertThrowsIllegalArg(() -> Frequency.of(Period.ofDays(-1)));
 assertThrowsIllegalArg(() -> Frequency.of(Period.ofMonths(-1)));
 assertThrowsIllegalArg(() -> Frequency.of(Period.of(0, -1, -1)));
 assertThrowsIllegalArg(() -> Frequency.of(Period.of(0, -1, 1)));
 assertThrowsIllegalArg(() -> Frequency.of(Period.of(0, 1, -1)));
 assertThrowsIllegalArg(() -> Frequency.ofDays(-1));
 assertThrowsIllegalArg(() -> Frequency.ofWeeks(-1));
 assertThrowsIllegalArg(() -> Frequency.ofMonths(-1));
 assertThrowsIllegalArg(() -> Frequency.ofYears(-1));
}

相关文章