本文整理汇总了Java中java.time.LocalDate.now方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDate.now方法的具体用法?Java LocalDate.now怎么用?Java LocalDate.now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldSelectMultipleDates
import java.time.LocalDate; //导入方法依赖的package包/类
@Test
public void shouldSelectMultipleDates() {
// Given
LocalDate now = LocalDate.now();
LocalDate tomorrow = now.plusDays(1);
LocalDate dayAfterTomorrow = tomorrow.plusDays(1);
LocalDate oneYearAfter = dayAfterTomorrow.plusYears(1);
DateSelectionModel model = new DateSelectionModel();
model.setSelectionMode(SelectionMode.MULTIPLE_DATES);
// When
model.selectRange(now, dayAfterTomorrow);
model.select(oneYearAfter);
// Then
assertFalse(model.isEmpty());
assertThat(model.getSelectedDates(), is(not(empty())));
assertThat(model.getSelectedDates().size(), is(equalTo(4)));
assertThat(model.getSelectedDates(), contains(now, tomorrow, dayAfterTomorrow, oneYearAfter));
assertThat(model.getLastSelected(), is(equalTo(oneYearAfter)));
assertTrue(model.isSelected(now));
assertTrue(model.isSelected(tomorrow));
assertTrue(model.isSelected(dayAfterTomorrow));
assertTrue(model.isSelected(oneYearAfter));
}
示例2: setDayChangeListener
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Sets a listener which checks if it is a new day, when the window becomes
* focused.
*
* @param primaryStage
* Stage to set listener on.
*/
public void setDayChangeListener(Stage primaryStage) {
// debug line, also comment out the line to reset 'today'
// today = LocalDate.now().plusDays(-1);
// focusDay.plusDays(-1);
today = LocalDate.now();
primaryStage.focusedProperty()
.addListener((observable, wasFocused, isFocused) -> {
if (isFocused) { // if becomes focused
if (!today.equals(LocalDate.now())) {
// then reset view
today = LocalDate.now();
// Also update focusDay, before refreshing.
focusDay = today;
setupGridPane(today);
}
}
});
}
示例3: initialize
import java.time.LocalDate; //导入方法依赖的package包/类
@Override
public void initialize(URL location, ResourceBundle resources) {
LocalDate today = LocalDate.now();
List<String> lines = new LinkedList<>();
lines.add("// Created on " + today);
lines.add(Resource.PACKAGE_STATEMENT);
lines.add("");
lines.add("public class YOUR_CLASS_NAME_HERE implements Runnable {");
lines.add(" @Override");
lines.add(" public void run() {");
lines.add(" // YOUR CODE HERE");
lines.add(" }");
lines.add("}");
lines.forEach(line -> textArea.appendText(line + "\n"));
testBase = TestBase.INSTANCE;
}
示例4: getItemSearchStatisticsAsync
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* 异步获取每日,每周,每月的统计数据
* @return 统计列表包含每日,每周,每月的统计数据
*/
private List<ItemSearchStatisticDTO> getItemSearchStatisticsAsync() {
List<ItemSearchStatisticDTO> itemSearchStatisticDTOList = new ArrayList<>(30);
int size = 10;
// 每日
LocalDate todayDate = LocalDate.now();
Future<List<Object[]>> itemDailySearchStatistics = findDateSearchStatistics(todayDate.toString(), size);
// 每周
LocalDate beforeWeekDate = todayDate.plusDays(-7);
Future<List<Object[]>> itemWeeklySearchStatistics = findDateSearchStatistics(beforeWeekDate.toString(), size);
// 每月
LocalDate beforeMonthDate = todayDate.plusMonths(-30);
Future<List<Object[]>> itemMonthlySearchStatistics = findDateSearchStatistics(beforeMonthDate.toString(), size);
fillItemSearchStatisticList(itemSearchStatisticDTOList, itemDailySearchStatistics, ItemSearchStatisticDTO.DAILY);
fillItemSearchStatisticList(itemSearchStatisticDTOList, itemWeeklySearchStatistics, ItemSearchStatisticDTO.WEEKLY);
fillItemSearchStatisticList(itemSearchStatisticDTOList, itemMonthlySearchStatistics, ItemSearchStatisticDTO.MONTHLY);
return itemSearchStatisticDTOList;
}
示例5: removeOldPersistentTokens
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Persistent Token are used for providing automatic authentication, they should be automatically deleted after
* 30 days.
* <p>
* This is scheduled to get fired everyday, at midnight.
* </p>
*/
@Scheduled(cron = "0 0 0 * * ?")
public void removeOldPersistentTokens() {
LocalDate now = LocalDate.now();
persistentTokenRepository.findByTokenDateBefore(now.minusMonths(1)).forEach(token -> {
log.debug("Deleting token {}", token.getSeries());
User user = token.getUser();
user.getPersistentTokens().remove(token);
persistentTokenRepository.delete(token);
});
}
示例6: setLocalDateFieldValueAndVerify
import java.time.LocalDate; //导入方法依赖的package包/类
@Test
public void setLocalDateFieldValueAndVerify() {
FieldAccess<Foo> access = ClassAccessFactory.get(Foo.class);
Foo obj = new Foo();
LocalDate localDate = LocalDate.now();
access.setField(obj, access.fieldIndex("localDate"), localDate);
assertThat(obj.getLocalDate(), equalTo(localDate));
}
示例7: setLocalDatePositional
import java.time.LocalDate; //导入方法依赖的package包/类
@Test
public void setLocalDatePositional() {
final LocalDate value = LocalDate.now();
final Iterator<Value<?>> it = ps.setLocalDate(0, value).params().iterator();
assertEquals(new LocalDateValue(value), it.next());
assertFalse(it.hasNext());
}
示例8: create
import java.time.LocalDate; //导入方法依赖的package包/类
public User create(String email, Set<User.Role> roles) {
User user = new User(email, roles, LocalDate.now());
// If we get a non null value that means the user already exists in the Map.
if (null != userMap.putIfAbsent(user.getEmail(), user)) {
return null;
}
return user;
}
示例9: InMemBookingRepository
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Initialize the in-memory Booking Repository with sample Map
*/
public InMemBookingRepository() {
entities = new HashMap();
Booking booking = new Booking("1", "Booking 1", "1", "1", "1", LocalDate.now(), LocalTime.now());
entities.put("1", booking);
Booking booking2 = new Booking("2", "Booking 2", "2", "2", "2", LocalDate.now(), LocalTime.now());
entities.put("2", booking2);
}
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:11,代码来源:InMemBookingRepository.java
示例10: removeOldPersistentTokens
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Persistent Token are used for providing automatic authentication, they should be automatically deleted after
* 30 days.
* <p>
* This is scheduled to get fired everyday, at midnight.
*/
@Scheduled(cron = "0 0 0 * * ?")
public void removeOldPersistentTokens() {
LocalDate now = LocalDate.now();
persistentTokenRepository.findByTokenDateBefore(now.minusMonths(1)).forEach(token -> {
log.debug("Deleting token {}", token.getSeries());
User user = token.getUser();
user.getPersistentTokens().remove(token);
persistentTokenRepository.delete(token);
});
}
示例11: now_ZoneId
import java.time.LocalDate; //导入方法依赖的package包/类
@Test
public void now_ZoneId() {
ZoneId zone = ZoneId.of("UTC+01:02:03");
LocalDate expected = LocalDate.now(Clock.system(zone));
LocalDate test = LocalDate.now(zone);
for (int i = 0; i < 100; i++) {
if (expected.equals(test)) {
return;
}
expected = LocalDate.now(Clock.system(zone));
test = LocalDate.now(zone);
}
assertEquals(test, expected);
}
示例12: shouldNotReturnMultiDay
import java.time.LocalDate; //导入方法依赖的package包/类
@Test
public void shouldNotReturnMultiDay() {
// given
LocalDate st = LocalDate.now();
LocalDate et = st;
entry.changeStartDate(st);
entry.changeEndDate(et);
// when
boolean multiDay = entry.isMultiDay();
// then
assertThat(multiDay, is(false));
}
示例13: now_Clock_allSecsInDay_beforeEpoch
import java.time.LocalDate; //导入方法依赖的package包/类
@Test
public void now_Clock_allSecsInDay_beforeEpoch() {
for (int i =-1; i >= -(2 * 24 * 60 * 60); i--) {
Instant instant = Instant.ofEpochSecond(i);
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
LocalDate test = LocalDate.now(clock);
assertEquals(test.getYear(), 1969);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), (i >= -24 * 60 * 60 ? 31 : 30));
}
}
示例14: testAdd
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Test the POST /v1/booking API
*
* @throws JsonProcessingException
*/
@Test
public void testAdd() throws JsonProcessingException {
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("name", "TestBkng 3");
requestBody.put("id", "3");
requestBody.put("userId", "3");
requestBody.put("restaurantId", "1");
requestBody.put("tableId", "1");
LocalDate nowDate = LocalDate.now();
LocalTime nowTime = LocalTime.now();
requestBody.put("date", nowDate);
requestBody.put("time", nowTime);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
objectMapper.findAndRegisterModules();
HttpEntity<String> entity = new HttpEntity<>(objectMapper.writeValueAsString(requestBody), headers);
ResponseEntity<Map> responseE = restTemplate.exchange("http://localhost:" + port + "/v1/booking", HttpMethod.POST, entity, Map.class, Collections.EMPTY_MAP);
assertNotNull(responseE);
// Should return created (status code 201)
assertEquals(HttpStatus.CREATED, responseE.getStatusCode());
//validating the newly created booking using API call
Map<String, Object> response
= restTemplate.getForObject("http://localhost:" + port + "/v1/booking/3", Map.class);
assertNotNull(response);
//Asserting API Response
String id = response.get("id").toString();
assertNotNull(id);
assertEquals("3", id);
String name = response.get("name").toString();
assertNotNull(name);
assertEquals("TestBkng 3", name);
boolean isModified = (boolean) response.get("isModified");
assertEquals(false, isModified);
String userId = response.get("userId").toString();
assertNotNull(userId);
assertEquals("3", userId);
String restaurantId = response.get("restaurantId").toString();
assertNotNull(restaurantId);
assertEquals("1", restaurantId);
String tableId = response.get("tableId").toString();
assertNotNull(tableId);
assertEquals("1", tableId);
String date1 = response.get("date").toString();
assertNotNull(date1);
String[] arrDate = date1.replace("[", "").replace("]", "").split(",");
assertEquals(nowDate, LocalDate.of(Integer.parseInt(arrDate[0].trim()),
Integer.parseInt(arrDate[1].trim()), Integer.parseInt(arrDate[2].trim())));
String time1 = response.get("time").toString();
assertNotNull(time1);
String[] arrTime = time1.replace("[", "").replace("]", "").split(",");
assertEquals(nowTime, LocalTime.of(Integer.parseInt(arrTime[0].trim()),
Integer.parseInt(arrTime[1].trim()), Integer.parseInt(arrTime[2].trim()), Integer.parseInt(arrTime[3].trim())));
}
开发者ID:PacktPublishing,项目名称:Mastering-Microservices-with-Java-9-Second-Edition,代码行数:66,代码来源:BookingControllerIntegrationTests.java
示例15: GanttTask
import java.time.LocalDate; //导入方法依赖的package包/类
public GanttTask(String name) {
this(name, LocalDate.now(), LocalDate.now().plusDays(1));
}