List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:ch.sdi.core.impl.data.converter.ConverterDate.java
/** * @see ch.sdi.core.intf.FieldConverter#convert(java.lang.String) *///from w w w. ja v a2s .co m @Override public Date convert(String aValue) throws SdiException { if (!StringUtils.hasText(aValue)) { myLog.debug("Given value is null"); return null; } DateFormat df; if (StringUtils.hasText(myDatePattern)) { df = new SimpleDateFormat(myDatePattern); } else { df = new SimpleDateFormat(); } // if..else StringUtils.hasText( myPattern ) Date result; try { result = df.parse(aValue); } catch (ParseException t) { throw new SdiException("Problems converting date: " + aValue + "; myDatePattern: " + myDatePattern, SdiException.EXIT_CODE_PARSE_ERROR); } return result; }
From source file:com.ibm.jaql.json.type.JsonDate.java
/** Sets the date represented by this <code>JsonDate</code> object to the specified value. * /*from ww w . j av a 2 s . co m*/ * @param date string representation of the date * @param format formatter to parse the date * * @throws UndeclaredThrowableException when a parse error occurs */ protected void set(String date, DateFormat format) { try { synchronized (format) // TODO: write our own parser code that is thread safe? { // FIXME: add timezone support this.millis = format.parse(date).getTime(); } } catch (java.text.ParseException ex) { throw new java.lang.reflect.UndeclaredThrowableException(ex); } }
From source file:th.co.geniustree.dental.controller.LotController.java
@RequestMapping(value = "/countsearchlot", method = RequestMethod.POST) public long countSearchLot(@RequestBody SearchData searchData) throws ParseException { long count = 0; String keyword = searchData.getKeyword(); String searchBy = searchData.getSearchBy(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US); if ("Name".equals(searchBy)) { count = lotRepo.count(LotSpec.nameStaffReamLike("%" + keyword + "%")); }/*from ww w . ja v a 2s.c o m*/ if ("DateIn".equals(searchBy)) { Date keywordDate = df.parse(keyword); count = lotRepo.count(LotSpec.dateInBetween(keywordDate)); } if ("DateOut".equals(searchBy)) { Date keywordDate = df.parse(keyword); count = lotRepo.count(LotSpec.dateOutBetween(keywordDate)); } return count; }
From source file:guru.nidi.atlassian.remote.jira.rest.JiraRestService.java
private Calendar calendar(String value) { if (value == null) { return null; }// ww w . ja v a2 s . co m try { DateFormat format = (value.length() == 10) ? new SimpleDateFormat("yyyy-MM-dd") : new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Date date = format.parse(value); Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; } catch (ParseException e) { return null; } }
From source file:com.algomedica.service.LicenseManagerServiceImpl.java
/** * @param oldExpiryDate/* w ww. j ava2 s .c om*/ * @param lsExipryDays * @return * @throws ParseException */ private Date calculateExpiryDate(long lsExipryDays) throws ParseException { Calendar c = Calendar.getInstance(); // starts with today's date and c.add(Calendar.DAY_OF_YEAR, Integer.valueOf(String.valueOf(lsExipryDays))); DateFormat outputFormatter = new SimpleDateFormat("MM/dd/yyyy"); Date date = c.getTime(); date = outputFormatter.parse(outputFormatter.format(date.getTime())); return date; }
From source file:DateValidator.java
/** * <p>Checks if the field is a valid date. The <code>Locale</code> is * used with <code>java.text.DateFormat</code>. The setLenient method * is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param locale The locale to use for the date format, defaults to the default * system default if null./*from www.j ava 2 s. c om*/ * @return true if the date is valid. */ public boolean isValid(String value, Locale locale) { if (value == null) { return false; } DateFormat formatter = null; if (locale != null) { formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale); } else { formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); } formatter.setLenient(false); try { formatter.parse(value); } catch (ParseException e) { return false; } return true; }
From source file:com.algomedica.service.LicenseManagerServiceImpl.java
/** * @param oldExpiryDate//from w w w . j a v a 2 s . c o m * @param lsExipryDays * @return * @throws ParseException */ private Date calculateExpiryDate(Date oldExpiryDate, long lsExipryDays) throws ParseException { Calendar c = Calendar.getInstance(); // starts with today's date and c.setTime(oldExpiryDate); c.add(Calendar.DAY_OF_YEAR, Integer.valueOf(String.valueOf(lsExipryDays))); DateFormat outputFormatter = new SimpleDateFormat("MM/dd/yyyy"); Date date = c.getTime(); date = outputFormatter.parse(outputFormatter.format(date.getTime())); return date; }
From source file:com.luna.common.repository.search.SearchUserRepository2WithRepository2ImpIT.java
@Test public void testEqForDate() throws ParseException { int count = 15; String dateStr = "2012-01-15 16:59:00"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < count; i++) { User user = createUser();// www . j a va 2 s. c o m user.setRegisterDate(df.parse(dateStr)); userRepository2.save(user); } Map<String, Object> searchParams = new HashMap<String, Object>(); searchParams.put("registerDate_eq", dateStr); SearchRequest search = new SearchRequest(searchParams); assertEquals(count, userRepository2.count(search)); }
From source file:net.iubris.ipc_d3.cap.CamelizeSomeFieldsAndExtractInformazioniStoricheDates.java
private JSONArray getTimes(JSONObject jsonObject) throws ParseException { DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String date = "1970-01-01"; JSONArray times = new JSONArray(); String apertura = jsonObject.getString("apertura"); long startingTimeEpoch = 0; if (apertura.isEmpty()) apertura = "19.00"; // default startingTimeEpoch = sdf.parse(date + " " + apertura.replace(".", ":")).getTime(); String chiusura = jsonObject.getString("chiusura"); long endingTimeEpoch = 0; if (chiusura.isEmpty()) chiusura = "1.00"; // default double parsedEndingTime = Double.parseDouble(chiusura); if (parsedEndingTime >= 0f && parsedEndingTime < 6f) // we are in next day date = "1970-01-02"; endingTimeEpoch = sdf.parse(date + " " + chiusura.replace(".", ":")).getTime(); String startingTimeEpoched = "" + startingTimeEpoch; String endingTimeEpoched = "" + endingTimeEpoch; JSONObject et = new JSONObject(); et.put("starting_time", startingTimeEpoched); et.put("ending_time", endingTimeEpoched); times.put(et);/* ww w.j a va2s .c o m*/ return times; }
From source file:org.openmrs.module.vcttrac.web.controller.VCTReceptionOfResultController.java
/** * Auto generated method comment// w w w. ja va2 s . co m * * @param request * @return */ /*private Person saveDateOfReceptionOfResults(HttpServletRequest request) { VCTModuleService service; VCTClient client = null; Date resultReceivedOn; Obs hivTestConstruct; Obs dateResultOfHivTestReceived = new Obs(); try { service = (VCTModuleService) ServiceContext.getInstance().getService(VCTModuleService.class); client = service.getClientByCodeTest(request.getParameter("clientCode")); resultReceivedOn = df.parse(request.getParameter("dateHivTestResultReceived")); hivTestConstruct = client.getResultObs(); log .info(">>>>>VCT>>Result>>Reception>>From>>>> Trying to save the dateResultOfHivTestReceived for Person#" + client.getClient().getPersonId() + "..."); dateResultOfHivTestReceived.setCreator(Context.getAuthenticatedUser()); dateResultOfHivTestReceived.setDateCreated(new Date()); dateResultOfHivTestReceived.setLocation(hivTestConstruct.getLocation()); dateResultOfHivTestReceived.setPerson(client.getClient()); dateResultOfHivTestReceived.setConcept(Context.getConceptService().getConcept( VCTTracUtil.getDateResultOfHivTestReceivedConceptId())); dateResultOfHivTestReceived.setValueDatetime(resultReceivedOn); dateResultOfHivTestReceived.setObsDatetime(resultReceivedOn); hivTestConstruct.addGroupMember(dateResultOfHivTestReceived); Context.getObsService().saveObs(hivTestConstruct, "Reception of result"); log.info(">>>>>VCT>>Result>>Reception>>From>>>> Obs dateResultOfHivTestReceived saved successfully."); client.setArchived(true); service.saveVCTClient(client); log.info(">>>>>VCT>>Result>>Reception>>From>>>> Client Archived successfully."); } catch (Exception e) { log.error(">>>>>>>>>>>>VCT>>Result>>Reception>>Form>>>> An error occured : "+e.getMessage()); e.printStackTrace(); } return client.getClient(); }*/ private void addNumberOfCondomsTaken(Obs o, HttpServletRequest request) throws Exception { if (request.getParameter("numberOfCondom") != null) { DateFormat df = Context.getDateFormat(); Date obsDatetime = df.parse(request.getParameter("dateHivTestResultReceived")); Obs obs5 = new Obs(); obs5.setPerson(o.getPerson()); obs5.setCreator(Context.getAuthenticatedUser()); obs5.setDateCreated(new Date()); obs5.setLocation(o.getLocation()); obs5.setObsDatetime(obsDatetime); obs5.setConcept(Context.getConceptService() .getConcept(VCTConfigurationUtil.getNumberOfCondomsTakenConceptId())); obs5.setValueNumeric(Double.valueOf(request.getParameter("numberOfCondom"))); obs5.setObsGroup(o); Context.getObsService().saveObs(obs5, null); } }