本文整理匯總了Java中java.time.LocalDate.minus方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.minus方法的具體用法?Java LocalDate.minus怎麽用?Java LocalDate.minus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.minus方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRangeOfLocalDates
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "localDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
final Range<LocalDate> range = Range.of(start, end, step);
final Array<LocalDate> array = range.toArray(parallel);
final boolean ascend = start.isBefore(end);
final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.DAYS.between(start, end)) / (double)step.getDays());
Assert.assertEquals(array.length(), expectedLength);
Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
LocalDate expected = null;
for (int i=0; i<array.length(); ++i) {
final LocalDate actual = array.getValue(i);
expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
Assert.assertEquals(actual, expected, "Value matches at " + i);
Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
}
}
示例2: testRangeOfLocalDates
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "LocalDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
final boolean ascend = start.isBefore(end);
final Range<LocalDate> range = Range.of(start, end, step, v -> v.getDayOfWeek() == DayOfWeek.MONDAY);
final Array<LocalDate> array = range.toArray(parallel);
final LocalDate first = array.first(v -> true).map(ArrayValue::getValue).get();
final LocalDate last = array.last(v -> true).map(ArrayValue::getValue).get();
Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
int index = 0;
LocalDate value = first;
while (ascend ? value.isBefore(last) : value.isAfter(last)) {
final LocalDate actual = array.getValue(index);
Assert.assertEquals(actual, value, "Value matches at " + index);
Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
value = ascend ? value.plus(step) : value.minus(step);
while (value.getDayOfWeek() == DayOfWeek.MONDAY) value = ascend ? value.plus(step) : value.minus(step);
index++;
}
}
示例3: bepaalDatum
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* bepaald de nieuwe datum door van de meegegeven datum het aantal meegegeven dagen af te trekken
* @param datum peilDatum
* @param minus aantal dagen voor peildatum
* @return bepaalde datum
*/
public static Integer bepaalDatum(final int datum, final int minus) {
final Integer minimaleDatum = bepaalEindDatumStrengOfBeginDatumSoepel(datum, false);
final LocalDate minimaleDate = vanIntegerNaarLocalDate(minimaleDatum);
final LocalDate nieuweDate = minimaleDate.minus(minus, ChronoUnit.DAYS);
final String formattedDateString = FORMATTER.format(nieuweDate);
return Integer.parseInt(formattedDateString);
}
示例4: initialize
import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public void initialize(URL location, ResourceBundle resources) {
diag = new Dialog();
diag.getDialogPane().setContent(borderPane);
diag.getDialogPane().setBackground(Background.EMPTY);
diag.setResizable(true);
UIUtils.setIcon(diag);
diag.setTitle("Export senor data to CSV");
// date
endPicker.disableProperty().bind(nowCheck.selectedProperty());
dateInput.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
try {
SimpleDateFormat sdf = new SimpleDateFormat(newValue);
dateLabel.setText(sdf.format(new Date()));
validFormat.set(true);
} catch (IllegalArgumentException ex) {
dateLabel.setText("Invalid format!");
validFormat.set(false);
}
});
// trigger
String cur = dateInput.getText();
dateInput.textProperty().set("");
dateInput.textProperty().set(cur);
endPicker.setValue(LocalDate.now());
LocalDate s = LocalDate.now();
s = s.minus(7, ChronoUnit.DAYS);
startPicker.setValue(s);
// Bug: can not bind same data on 2 lists
sensorList.getItems().addAll(store.getSensors());
sensorList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
sensorSelected.set(newValue != null);
});
canExport.bind(sensorSelected.and(validFormat));
ButtonType closeButton = new ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE);
ButtonType exportButton = new ButtonType("Export", ButtonBar.ButtonData.OK_DONE);
diag.getDialogPane().getButtonTypes().addAll(closeButton, exportButton);
diag.getDialogPane().lookupButton(exportButton).disableProperty().bind(canExport.not());
showDialog();
}
示例5: getPreviousDay
import java.time.LocalDate; //導入方法依賴的package包/類
/**
* 獲取前 i 天日期
*
* @return
*/
public static LocalDate getPreviousDay ( int i ) {
LocalDate today = LocalDate.now();
return today.minus( i , ChronoUnit.DAYS );
}