- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.YearMonth.until()
方法的一些代码示例,展示了YearMonth.until()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.until()
方法的具体详情如下:
包路径:java.time.YearMonth
类名称:YearMonth
方法名:until
[英]Calculates the period between this year-month and another year-month in terms of the specified unit.
This calculates the period between two year-months in terms of a single unit. The start and end points are this and the specified year-month. The result will be negative if the end is before the start. The Temporal passed to this method must be a YearMonth. For example, the period in years between two year-months can be calculated using startYearMonth.until(endYearMonth, YEARS).
The calculation returns a whole number, representing the number of complete units between the two year-months. For example, the period in decades between 2012-06 and 2032-05 will only be one decade as it is one month short of two decades.
This method operates in association with TemporalUnit#between. The result of this method is a long representing the amount of the specified unit. By contrast, the result of between is an object that can be used directly in addition/subtraction:
long period = start.until(end, YEARS); // this method
dateTime.plus(YEARS.between(start, end)); // use in plus/minus
The calculation is implemented in this method for ChronoUnit. The units MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS are supported. Other ChronoUnit values will throw an exception.
If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.between(Temporal, Temporal)passing this as the first argument and the input temporal as the second argument.
This instance is immutable and unaffected by this method call.
[中]根据指定的单位计算本年月份和另一年月份之间的期间。
这将根据单个单元计算两个月之间的时间。开始点和结束点为本月和指定的年-月。如果结束早于开始,结果将为负值。传递给此方法的时间必须为一年一个月。例如,可以使用startYearMonth计算两个年月之间的年周期。直到(年底月,年)。
计算结果返回一个整数,表示两年内的完整单元数。例如,从2012-06年到2032-05年的几十年期间将只有十年,因为距离二十年只差一个月。
该方法与TemporalUnit#between结合使用。此方法的结果是一个长的字符,表示指定单位的数量。相比之下,between的结果是一个可以直接用于加法/减法的对象:
long period = start.until(end, YEARS); // this method
dateTime.plus(YEARS.between(start, end)); // use in plus/minus
该计算是在ChronoUnit的这种方法中实现的。支持单位月、年、数十年、世纪、千年和年代。其他ChronoUnit值将引发异常。
如果该单元不是ChronoUnit,则通过调用TemporalUnit获得该方法的结果。(时态,时态)将其作为第一个参数传递,将输入时态作为第二个参数传递。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: stackoverflow.com
public static final long getMonthsDifference(Date date1, Date date2) {
YearMonth m1 = YearMonth.from(date1.toInstant());
YearMonth m2 = YearMonth.from(date2.toInstant());
return m1.until(m2, ChronoUnit.MONTHS) + 1;
}
代码示例来源:origin: owlike/genson
private static long getEpochMonth(YearMonth yearMonth){
return EPOCH_YEAR_MONTH.until(yearMonth, ChronoUnit.MONTHS);
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
test("June, 1999", "April, 2002");
}
private static void test(String fromMonthYear, String toMonthYear) {
DateTimeFormatter monthYearFormat = DateTimeFormatter.ofPattern("MMMM, uuuu");
YearMonth from = YearMonth.parse(fromMonthYear, monthYearFormat);
YearMonth to = YearMonth.parse(toMonthYear , monthYearFormat);
long months = from.until(to, ChronoUnit.MONTHS);
System.out.printf("%d years and %d months%n", months / 12, months % 12);
}
代码示例来源:origin: OpenGamma/Strata
private double numberOfMonths(YearMonth month) {
return YearMonth.from(valuationDate).until(month, MONTHS);
}
代码示例来源:origin: OpenGamma/Strata
private DoubleArray buildNodeTimes(LocalDate valuationDate, CurveMetadata metadata) {
if (metadata.getXValueType().equals(ValueType.YEAR_FRACTION)) {
return DoubleArray.of(getParameterCount(), i -> {
LocalDate nodeDate = ((DatedParameterMetadata) metadata.getParameterMetadata().get().get(i)).getDate();
return getDayCount().get().yearFraction(valuationDate, nodeDate);
});
} else if (metadata.getXValueType().equals(ValueType.MONTHS)) {
return DoubleArray.of(getParameterCount(), i -> {
LocalDate nodeDate = ((DatedParameterMetadata) metadata.getParameterMetadata().get().get(i)).getDate();
return YearMonth.from(valuationDate).until(YearMonth.from(nodeDate), MONTHS);
});
} else {
throw new IllegalArgumentException("Metadata XValueType should be YearFraction or Months in curve definition");
}
}
代码示例来源:origin: OpenGamma/Strata
public void value_multiplicative() {
InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_MULTIPLICATIVE_DEF);
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
double valueComputed = curveComputed.yValue(nbMonths);
int x = (int) ((nbMonths + 12) % 12);
double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths);
double adj = SEASONALITY_MULTIPLICATIVE_COMP_2.get(x);
double valueExpected = valueNoAdj * adj;
assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE);
}
}
代码示例来源:origin: OpenGamma/Strata
public void test_value() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
double valueComputed = INSTANCE.value(TEST_OBS[i]);
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
double valueExpected;
if (USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble();
} else {
double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS);
valueExpected = CURVE_INFL.yValue(x);
}
assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i);
}
}
代码示例来源:origin: OpenGamma/Strata
public void value_additive() {
InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_ADDITIVE_DEF);
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
double valueComputed = curveComputed.yValue(nbMonths);
int x = (int) ((nbMonths + 12) % 12);
double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths);
DoubleArray seasonalityAdditiveCompounded =
seasonalityCompounded(VAL_DATE_2, LAST_FIX_MONTH_2, SEASONALITY_ADDITIVE, (v, a) -> v + a);
double adj = seasonalityAdditiveCompounded.get(x);
double valueExpected = valueNoAdj + adj;
assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE);
}
}
代码示例来源:origin: OpenGamma/Strata
public void test_value_futfixing() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
double valueComputed = INSTANCE_WITH_FUTFIXING.value(TEST_OBS[i]);
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
double valueExpected;
if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble();
} else {
double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
valueExpected = CURVE_INFL2.yValue(x);
}
assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i);
}
}
代码示例来源:origin: OpenGamma/Strata
private static DoubleArray seasonalityCompounded(
LocalDate valDate, YearMonth fixingMonth, DoubleArray seasonality,
DoubleBinaryOperator adjustmentFunction) {
double nbMonths = YearMonth.from(valDate).until(fixingMonth, MONTHS);
double[] seasonalityCompoundedArray = new double[12];
int lastMonthIndex = fixingMonth.getMonth().getValue() - 2;
seasonalityCompoundedArray[(int) ((nbMonths + 12 + 1) % 12)] =
seasonality.get((lastMonthIndex + 1) % 12);
for (int i = 1; i < 12; i++) {
int j = (int) ((nbMonths + 12 + 1 + i) % 12);
seasonalityCompoundedArray[j] = adjustmentFunction.applyAsDouble(
seasonalityCompoundedArray[(j - 1 + 12) % 12], seasonality.get((lastMonthIndex + 1 + i) % 12));
}
return DoubleArray.ofUnsafe(seasonalityCompoundedArray);
}
代码示例来源:origin: OpenGamma/Strata
public void test_value_parameter_sensitivity() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
if (!USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d);
CurrencyParameterSensitivities psComputed = INSTANCE.parameterSensitivity(ptsExpected);
double x = YearMonth.from(VAL_DATE).until(fixingMonth, MONTHS);
UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL.yValueParameterSensitivity(x));
CurrencyParameterSensitivities psExpected =
sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity());
assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i);
}
}
}
代码示例来源:origin: OpenGamma/Strata
public void parameter_sensitivity_additive() {
InflationNodalCurve curve = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_ADDITIVE_DEF);
double shift = 1.0E-2;
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
UnitParameterSensitivity psComputed = curve.yValueParameterSensitivity(nbMonths);
for (int j = 0; j < TIMES.size(); j++) {
double[] valuePM = new double[2];
for (int pm = 0; pm < 2; pm++) {
DoubleArray shiftedValues = VALUES.with(j, VALUES.get(j) + (1 - 2 * pm) * shift);
InterpolatedNodalCurve intCurveShifted = InterpolatedNodalCurve.of(METADATA, TIMES, shiftedValues, INTERPOLATOR);
InflationNodalCurve seaCurveShifted =
InflationNodalCurve.of(intCurveShifted, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_ADDITIVE_DEF);
valuePM[pm] = seaCurveShifted.yValue(nbMonths);
}
assertEquals(psComputed.getSensitivity().get(j), (valuePM[0] - valuePM[1]) / (2 * shift), TOLERANCE_DELTA);
}
}
}
代码示例来源:origin: OpenGamma/Strata
public void test_value_parameter_sensitivity_futfixing() {
for (int i = 0; i < TEST_MONTHS.length; i++) {
YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
if (!fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && !USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d);
CurrencyParameterSensitivities psComputed = INSTANCE_WITH_FUTFIXING.parameterSensitivity(ptsExpected);
double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL2.yValueParameterSensitivity(x));
CurrencyParameterSensitivities psExpected =
sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity());
assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i);
}
}
}
代码示例来源:origin: OpenGamma/Strata
public void parameter_sensitivity_multiplicative() {
InflationNodalCurve curve = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_MULTIPLICATIVE_DEF);
double shift = 1.0E-2;
for (int i = 1; i < TEST_MONTHS.length; i++) {
double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
UnitParameterSensitivity psComputed = curve.yValueParameterSensitivity(nbMonths);
for (int j = 0; j < TIMES.size(); j++) {
double[] valuePM = new double[2];
for (int pm = 0; pm < 2; pm++) {
DoubleArray shiftedValues = VALUES.with(j, VALUES.get(j) + (1 - 2 * pm) * shift);
InterpolatedNodalCurve intCurveShifted = InterpolatedNodalCurve.of(METADATA, TIMES, shiftedValues, INTERPOLATOR);
InflationNodalCurve seaCurveShifted =
InflationNodalCurve.of(intCurveShifted, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
SEASONALITY_MULTIPLICATIVE_DEF);
valuePM[pm] = seaCurveShifted.yValue(nbMonths);
}
assertEquals(psComputed.getSensitivity().get(j), (valuePM[0] - valuePM[1]) / (2 * shift), TOLERANCE_DELTA);
}
}
}
代码示例来源:origin: OpenGamma/Strata
double nbMonth = valuationMonth.until(lastMonth, MONTHS);
DoubleArray x = curveWithoutFixing.getXValues();
ArgChecker.isTrue(nbMonth < x.get(0), "The first estimation month should be after the last known index fixing");
此 map-reduce 用于计算“Hadoop:权威指南”中的示例每年和每月的平均温度 输出应该是 年[TAB]月[TAB]平均_温度 由于键(年+月)已经合并,是否可以使用 substring()
我想解析两个单独的字符串 "1982"和"SEP"进入java.time.YearMonth对象。 java.time.YearMonth.parse("1978 SEP", java.time.fo
在.Net Framework中,我们常用的时间类型是DateTime。直到.Net6微软加入了两个新的时间类型:DateOnly和TimeOnly,才弥补了之前的不足。 DateOnly :
本文整理了Java中java.time.YearMonth.with()方法的一些代码示例,展示了YearMonth.with()的具体用法。这些代码示例主要来源于Github/Stackoverfl
本文整理了Java中java.time.YearMonth.until()方法的一些代码示例,展示了YearMonth.until()的具体用法。这些代码示例主要来源于Github/Stackover
本文整理了Java中java.time.YearMonth.from()方法的一些代码示例,展示了YearMonth.from()的具体用法。这些代码示例主要来源于Github/Stackoverfl
本文整理了Java中java.time.YearMonth.of()方法的一些代码示例,展示了YearMonth.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/M
我正在使用 joda.time 的 YearMonth 对象,并希望在此对象中获取月份日期的最后一天。 yearMonth.monthOfYear().getMaximumValue(); //ret
我想找到等于或晚于当前 YearMonth 的月份 final YearMonth yearMonth = YearMonth.of(2020, 8); final boolean after = y
如何在实体中使用 YearMonth?我已经看到很多关于转换器的堆栈溢出答案?这仍然需要吗?如果需要的话如何? @Basic(optional = false) @NotNull @Column(na
我在解析代表年份和月份的特殊字符串时遇到问题,偏移量如下:2014-08+03:00 . 所需的输出是 YearMonth . 我已经测试过创建自定义 DateTimeFormatter有各种模式,但
本文整理了Java中java.time.YearMonth.()方法的一些代码示例,展示了YearMonth.()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven
本文整理了Java中java.time.YearMonth.compareTo()方法的一些代码示例,展示了YearMonth.compareTo()的具体用法。这些代码示例主要来源于Github/S
本文整理了Java中java.time.YearMonth.lengthOfMonth()方法的一些代码示例,展示了YearMonth.lengthOfMonth()的具体用法。这些代码示例主要来源于
本文整理了Java中java.time.YearMonth.minusMonths()方法的一些代码示例,展示了YearMonth.minusMonths()的具体用法。这些代码示例主要来源于Gith
本文整理了Java中java.time.YearMonth.now()方法的一些代码示例,展示了YearMonth.now()的具体用法。这些代码示例主要来源于Github/Stackoverflow
本文整理了Java中java.time.YearMonth.isBefore()方法的一些代码示例,展示了YearMonth.isBefore()的具体用法。这些代码示例主要来源于Github/Sta
本文整理了Java中java.time.YearMonth.getMonth()方法的一些代码示例,展示了YearMonth.getMonth()的具体用法。这些代码示例主要来源于Github/Sta
本文整理了Java中java.time.YearMonth.format()方法的一些代码示例,展示了YearMonth.format()的具体用法。这些代码示例主要来源于Github/Stackov
本文整理了Java中java.time.YearMonth.plus()方法的一些代码示例,展示了YearMonth.plus()的具体用法。这些代码示例主要来源于Github/Stackoverfl
我是一名优秀的程序员,十分优秀!