List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:com.oasis.test.driver.DriverServiceTest.java
private DriverSO getSo() { DriverSO so = new DriverSO(); so.setStatus(DriverStatus.NORMAL);//from ww w . jav a2 s .co m so.setLicense("A"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try { so.setPeriodStart(df.parse("2008-06-21")); so.setPeriodEnd(df.parse("2015-10-08")); } catch (ParseException e) { e.printStackTrace(); } return so; }
From source file:com.xumpy.thuisadmin.controllers.rest.FetchGraphiekOverview.java
@RequestMapping("/json/graphiek_overview") public @ResponseBody List<RekeningOverzicht> fetchGraphiekOverview(@RequestBody FinanceOverview financeOverview) throws ParseException { if (financeOverview.getBeginDatum() != null) { String strStartDate = financeOverview.getBeginDatum(); String strEindDate = financeOverview.getEindDatum(); DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Date startDate = format.parse(strStartDate); Date eindDate = format.parse(strEindDate); return bedragenSrv.graphiekBedrag(financeOverview.getRekening(), startDate, eindDate); } else {/*from w w w . ja v a2s . c o m*/ return null; } }
From source file:de.perdian.commons.lang.conversion.impl.converters.StringToDateConverter.java
protected Date parseUsingFormat(DateFormat dateFormat, String source) { try {/*from ww w . j av a2 s .c o m*/ return source == null ? null : dateFormat.parse(source); } catch (ParseException e) { StringBuilder errorMessage = new StringBuilder(); errorMessage.append("Cannot parse value '").append(source).append("' into "); errorMessage.append(" valid Date using format '").append(dateFormat); errorMessage.append("'"); throw new ConverterException(source, errorMessage.toString()); } }
From source file:com.xumpy.thuisadmin.controllers.rest.FetchGraphiekOverview.java
@RequestMapping("/json/graphiek_overzicht_per_groep") public @ResponseBody FinanceOverzichtGroep fetchGraphiekOverzichtPerGroep( @RequestBody FinanceOverview financeOverview) throws ParseException { if (financeOverview.getBeginDatum() != null) { String strStartDate = financeOverview.getBeginDatum(); String strEindDate = financeOverview.getEindDatum(); DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Date startDate = format.parse(strStartDate); Date eindDate = format.parse(strEindDate); Integer showPublicGroep = financeOverview.isShowPublicGroep() ? 1 : 0; return bedragenSrv.graphiekOverzichtGroep(startDate, eindDate, showPublicGroep); } else {/*from w w w.j a v a2 s . c o m*/ return null; } }
From source file:com.oasis.test.driver.DriverServiceTest.java
private DriverVO getVo() { DriverSO so = new DriverSO(); PageList<DriverVO> page = service.getPageList(so); DriverVO vo = page.getList().get(0); vo.setName(""); vo.setCode("zh001"); vo.setAllowedTruck(AllowedTruck.B);/* w w w . ja v a2s. c o m*/ vo.setLicense("A 7985"); vo.setLicenseDate(Calendar.getInstance().getTime()); vo.setStatus(DriverStatus.NORMAL); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try { vo.setPeriodStart(df.parse("2003-06-21")); vo.setPeriodEnd(df.parse("2017-10-08")); } catch (ParseException e) { e.printStackTrace(); } return vo; }
From source file:ru.tsystems.project.BuyTicketTest.java
@Before public void setUp() throws ParseException { httpRequest = new MockHttpServletRequest("POST", "/contexts"); httpRequest.getSession().setAttribute("cityFrom", "Saint-Peterburg"); httpRequest.getSession().setAttribute("cityTo", "Moscow"); httpRequest.setParameter("firstName", "Ivan"); httpRequest.setParameter("lastName", "Ivanov"); httpRequest.setParameter("birthday", "1976-03-16"); httpRequest.setParameter("index", "0"); pass = new Passenger(); pass.setFirstName("Ivan"); pass.setLastName("Ivanov"); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date birthday = format.parse("1976-03-16"); pass.setBirthday(birthday);//from w ww.ja va 2 s.co m list = new ArrayList<>(); routeEntity = new RouteEntity(); routeEntity.setRouteEntity_id(1); list.add(routeEntity); route = new Route(); route.setRouteId(1); routeEntity.setRoute(route); httpRequest.getSession().setAttribute("tickets", list); }
From source file:com.xumpy.thuisadmin.controllers.rest.FetchGraphiekOverview.java
@RequestMapping("/json/report_overzicht_groep_bedragen") public @ResponseBody OverzichtGroepBedragenTotal fetchReportOverzichtGroepBedragen( @RequestBody OverzichtGroepBedragenInp overzichtGroepBedragenInp) throws ParseException { if (overzichtGroepBedragenInp.getBeginDatum() != null) { String strStartDate = overzichtGroepBedragenInp.getBeginDatum(); String strEindDate = overzichtGroepBedragenInp.getEindDatum(); DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Date startDate = format.parse(strStartDate); Date eindDate = format.parse(strEindDate); Integer showPublicGroep = overzichtGroepBedragenInp.isShowPublicGroep() ? 1 : 0; return bedragenSrv.rapportOverzichtGroepBedragen(overzichtGroepBedragenInp.getTypeGroepId(), overzichtGroepBedragenInp.getTypeGroepKostOpbrengst(), startDate, eindDate, showPublicGroep, overzichtGroepBedragenTotal); } else {/*from w ww .j av a 2s .c o m*/ return null; } }
From source file:com.exploringspatial.com.exploringspatial.dao.mapping.ConflictRowMapper.java
@Override public Conflict mapRow(ResultSet resultSet, int i) throws SQLException { final Conflict conflict = new Conflict(); conflict.setActor1(resultSet.getString(ConflictColumns.ACTOR1.name())); conflict.setActor2(resultSet.getString(ConflictColumns.ACTOR2.name())); conflict.setAdmin1(resultSet.getString(ConflictColumns.ADMIN1.name())); conflict.setAdmin2(resultSet.getString(ConflictColumns.ADMIN2.name())); conflict.setAdmin3(resultSet.getString(ConflictColumns.ADMIN3.name())); conflict.setAllyActor1(resultSet.getString(ConflictColumns.ALLY_ACTOR_1.name())); conflict.setAllyActor2(resultSet.getString(ConflictColumns.ALLY_ACTOR_2.name())); conflict.setCountry(resultSet.getString(ConflictColumns.COUNTRY.name())); final String date = resultSet.getString(ConflictColumns.EVENT_DATE.name()); if (date != null && !date.isEmpty()) { final DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); try {/* w ww . jav a2 s . com*/ conflict.setEventDate(dateFormat.parse(date)); } catch (ParseException e) { log.warn("Could not parse Date: '" + date + "'"); } } conflict.setEventIdCountry(resultSet.getString(ConflictColumns.EVENT_ID_CNTY.name())); conflict.setEventPk(resultSet.getLong(ConflictColumns.EVENT_ID_NO_CNTY.name())); conflict.setEventType(resultSet.getString(ConflictColumns.EVENT_TYPE.name())); conflict.setFatalities(resultSet.getInt(ConflictColumns.FATALITIES.name())); conflict.setGeoPrecision(resultSet.getInt(ConflictColumns.GEO_PRECIS.name())); conflict.setGwno(resultSet.getInt(ConflictColumns.GWNO.name())); conflict.setInter1(resultSet.getInt(ConflictColumns.INTER1.name())); conflict.setInter2(resultSet.getInt(ConflictColumns.INTER2.name())); conflict.setInteraction(resultSet.getInt(ConflictColumns.INTERACTION.name())); conflict.setLatitude(resultSet.getDouble(ConflictColumns.LATITUDE.name())); conflict.setLongitude(resultSet.getDouble(ConflictColumns.LONGITUDE.name())); conflict.setLocation(resultSet.getString(ConflictColumns.LOCATION.name())); conflict.setNotes(resultSet.getString(ConflictColumns.NOTES.name())); conflict.setSource(resultSet.getString(ConflictColumns.SOURCE.name())); conflict.setTimePrecision(resultSet.getInt(ConflictColumns.TIME_PRECISION.name())); conflict.setYear(resultSet.getInt(ConflictColumns.YEAR.name())); return conflict; }
From source file:com.netcracker.financeapp.controller.income.IncomeServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int value = Integer.parseInt(request.getParameter("value")); Date date = null;/* w w w . ja v a2s . c o m*/ try { DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); date = dateFormat.parse(request.getParameter("date")); } catch (ParseException ex) { Logger.getLogger(IncomeServlet.class.getName()).log(Level.SEVERE, null, ex); } String description = request.getParameter("description"); String typeName = request.getParameter("incomeType"); int typeId = typeService.getTypeByName(typeName).getIdType(); int transactionTypeId = typeService.getTypeByName(typeName).getIdParent(); int stateTypeId = typeService.getTypeByName("COMMITED").getIdType(); String from = request.getParameter("fromListVal"); Agent currentAgent = agentService.getAgentByName(from); String to = request.getParameter("toListVal"); BankCard currentBankCard = bankCardService.getBankCardByNumber(to); bankCardService.editCardAmount(currentBankCard.getIdCard(), currentBankCard.getAmount() + value); int incomeId = incomeService.insertIncome(value, description, date, typeId); if (incomeId > 0) { request.getRequestDispatcher("templates/success.jsp").forward(request, response); transactionService.insertTransaction(transactionTypeId, stateTypeId, currentAgent.getIdAgent(), currentBankCard.getIdCard(), incomeId); } else { request.getRequestDispatcher("templates/error.jsp").forward(request, response); } }
From source file:com.linuxbox.enkive.web.search.AbstractSearchWebScript.java
public Date parseDate(String s) throws ParseException { if (isEmpty(s)) { return null; }/*w ww. jav a 2s . c o m*/ ParseException firstException = null; for (DateFormat f : DATE_FORMATS) { try { return f.parse(s); } catch (ParseException e) { if (firstException == null) { firstException = e; } } } throw firstException; }