List of usage examples for java.time LocalDate parse
public static LocalDate parse(CharSequence text, DateTimeFormatter formatter)
From source file:Main.java
@Override public void start(Stage stage) { String pattern = "yyyy-MM-dd"; VBox vbox = new VBox(20); Scene scene = new Scene(vbox, 400, 400); stage.setScene(scene);//from w ww. j a v a 2s . c om DatePicker checkInDatePicker = new DatePicker(); StringConverter<LocalDate> converter = new StringConverter<LocalDate>() { DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern); @Override public String toString(LocalDate date) { if (date != null) { return dateFormatter.format(date); } else { return ""; } } @Override public LocalDate fromString(String string) { if (string != null && !string.isEmpty()) { return LocalDate.parse(string, dateFormatter); } else { return null; } } }; checkInDatePicker.setConverter(converter); checkInDatePicker.setPromptText(pattern.toLowerCase()); vbox.getChildren().add(checkInDatePicker); checkInDatePicker.requestFocus(); stage.show(); }
From source file:svc.data.citations.datasources.mock.MockCitationDataSourceIntegrationTest.java
@Test public void GetCitationByCitationNumberAndDOBSuccessful() throws ParseException { String dateString = "04/10/1992"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse(dateString, formatter); List<Citation> citations = mockCitationDataSource.getByCitationNumberAndDOB("13938567", date); assertThat(citations.get(0), is(notNullValue())); assertThat(citations.get(0).id, is(7)); }
From source file:org.mascherl.example.page.data.SignUpStep1Bean.java
@Past @NotNull//ww w .j a v a2 s .co m @JsonIgnore public LocalDate getDateOfBirthParsed() { try { return LocalDate.parse(dateOfBirth, DateTimeFormatter.ofPattern("yyyy-MM-dd")); } catch (RuntimeException e) { return null; } }
From source file:com.swcguild.serverinventory.test.ServerDaoTest.java
@Test public void addGetRemoveServerTest() { Server temp = new Server(); temp.setName("web01"); temp.setMake("Dell"); temp.setIp("123.44.55.11"); temp.setNumProcessors("4"); temp.setRam("128"); temp.setPurchaseDate(LocalDate.parse("2000-01-01", DateTimeFormatter.ISO_DATE)); dao.addServer(temp.getName(), temp); Server retServer = dao.getServer(temp.getName()); assertEquals(temp, retServer);/* w w w . j a va 2 s . com*/ dao.removeServer(temp.getName()); retServer = dao.getServer(temp.getName()); assertNull(retServer); }
From source file:org.sakaiproject.component.app.scheduler.jobs.cm.processor.sis.AbstractCMProcessor.java
public Date getDate(String str) { if (StringUtils.isBlank(str)) { return null; }/*from w ww . j a v a 2s. c om*/ DateTimeFormatter df = DateTimeFormatter.ofPattern(dateFormat); try { return Date.from(LocalDate.parse(str, df).atStartOfDay(ZoneId.systemDefault()).toInstant()); } catch (DateTimeParseException dtpe) { throw new RuntimeException("Cannot parse the date from: " + str, dtpe); } }
From source file:datojava.jcalendar.DJJCalendar.java
public void fechasOcupadas() throws IOException, ClientProtocolException, JSONException, ParseException { for (int i = 0; i < fechasOcupadasArray.length(); i++) { JSONObject obj = (JSONObject) fechasOcupadasArray.get(i); //Date date = formato.parse(obj.get("diasOcupados").toString()); LocalDate date = LocalDate.parse(obj.get("diasOcupados").toString(), formatter); Calendar calendar = new GregorianCalendar(date.getYear(), date.getMonthValue() - 1, date.getDayOfMonth());//from ww w . jav a 2 s .c om //Calendar calendar = new GregorianCalendar(2015,Calendar.DECEMBER,12); fechasOcupadas.add(calendar); } System.out.println("retorne el djj"); }
From source file:svc.data.citations.datasources.mock.MockCitationDataSourceIntegrationTest.java
@Test public void GetCitationsByDOBAndLicenseSuccessful() throws ParseException { String dateString = "05/18/1987"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse(dateString, formatter); List<Citation> citations = mockCitationDataSource.getByLicenseAndDOB("S878479512", "MO", date); assertThat(citations, is(notNullValue())); assertThat(citations.size(), is(3)); assertThat(citations.get(0).first_name, is("Brenda")); }
From source file:com.haulmont.chile.core.datatypes.impl.LocalDateDatatype.java
@Override public LocalDate parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; }// ww w .j a v a2s .co m FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatPattern); return LocalDate.parse(value.trim(), formatter); }
From source file:svc.data.citations.datasources.mock.MockCitationDataSourceTest.java
@SuppressWarnings("unchecked") @Test/*from w ww. j a va 2s. c om*/ public void returnsCitationGivenCitationNumberAndDOB() throws ParseException { final Violation VIOLATION = new Violation(); VIOLATION.id = 4; final List<Violation> VIOLATIONS = Lists.newArrayList(VIOLATION); final Citation CITATION = new Citation(); CITATION.id = 3; final String CITATIONNUMBER = "F3453"; String dateString = "08/05/1965"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse(dateString, formatter); when(jdbcTemplate.query(Matchers.anyString(), Matchers.anyMap(), Matchers.<RowMapper<Citation>>any())) .thenReturn(Lists.newArrayList(CITATION)); List<Citation> citations = mockCitationDataSource.getByCitationNumberAndDOB(CITATIONNUMBER, date); when(violationManagerMock.getViolationsByCitationNumber(Matchers.anyString())).thenReturn(VIOLATIONS); assertEquals(citations.size(), 1); assertThat(citations.get(0).id, is(3)); }
From source file:org.openlmis.converter.DirectDateTypeConverter.java
private String parseDate(String value) { LocalDate date = null;/*from w w w . ja v a 2s . com*/ for (String format : DATE_FORMATS) { try { date = LocalDate.parse(value, DateTimeFormatter.ofPattern(format)); break; } catch (DateTimeParseException exp) { date = null; logger.debug("Can't parse date {} with format {}", value, format, exp); } } return null == date ? null : date.format(DateTimeFormatter.ISO_DATE); }