List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:com.handpay.ibenefit.framework.util.WebUtils.java
public static Map<String, Object> getSearchParameterMap(HttpServletRequest request, Class DomainObjecClass) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Map<String, Object> parameterMap = new HashMap(); Map requestMap = getParametersStartingWith(request, DEFAULT_SEARCH_PREFIX); boolean matchAll = true; PropertyDescriptor[] beandesc = PropertyUtils.getPropertyDescriptors(DomainObjecClass); for (int i = 0; i < beandesc.length; i++) { PropertyDescriptor descriptor = beandesc[i]; String propertyName = descriptor.getName(); Class propertyClass = descriptor.getPropertyType(); if ("class".equals(propertyName)) { continue; }// w w w. j a v a 2 s .c o m if (propertyClass == Date.class) { String after = (String) requestMap.get(propertyName + "After"); if (after != null && after.trim().length() > 0) { try { Date afterDate = dateFormat.parse(after); parameterMap.put(propertyName + "After", afterDate); } catch (Exception e) { } } String befor = (String) requestMap.get(propertyName + "Befor"); if (befor != null && befor.trim().length() > 0) { try { Date beforDate = dateFormat.parse(befor); // to the end of the day long dayTail = beforDate.getTime() + 24 * 3600 * 1000 - 1; parameterMap.put(propertyName + "Befor", new Date(dayTail)); } catch (Exception e) { } } } else if (propertyClass == String.class) { String value = (String) requestMap.get(propertyName); if (value != null && value.trim().length() > 0) { if (matchAll) { parameterMap.put(propertyName, "%" + value + "%"); } else { parameterMap.put(propertyName, value + "%"); } } } else if (propertyClass == Long.class) { String value = (String) requestMap.get(propertyName); if (value != null && value.trim().length() > 0) { parameterMap.put(propertyName, Long.parseLong(value)); } } else if (propertyClass == Integer.class) { String value = (String) requestMap.get(propertyName); if (value != null && value.trim().length() > 0) { parameterMap.put(propertyName, Integer.parseInt(value)); } } else if (propertyClass == Double.class) { String value = (String) requestMap.get(propertyName); if (value != null && value.trim().length() > 0) { parameterMap.put(propertyName, Double.parseDouble(value)); } } else if (propertyClass == Float.class) { String value = (String) requestMap.get(propertyName); if (value != null && value.trim().length() > 0) { parameterMap.put(propertyName, Float.parseFloat(value)); } } else if (propertyClass == Boolean.class) { String value = (String) requestMap.get(propertyName); if (value != null && value.trim().length() > 0) { parameterMap.put(propertyName, Boolean.parseBoolean(value)); } } } return parameterMap; }
From source file:nz.co.senanque.madura.datetime.HolidayCalendarImpl2Test.java
/** * Test method for {@link nz.co.senanque.madura.datetime.HolidayCalendarImpl#isHoliday(java.util.Date)}. *///from w w w . j a va2 s. c o m @Test public void testIsHoliday() throws Exception { Holiday holiday = m_holiday; DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); Date anzac = df.parse("2008-04-25T09:00:00.00"); assertTrue(holiday.isHoliday(anzac)); anzac = df.parse("2010-04-25T15:00:00"); assertFalse(holiday.isHoliday(anzac)); Date easterMonday = java.sql.Date.valueOf("2008-03-24"); assertTrue(holiday.isHoliday(easterMonday)); Date goodFriday = java.sql.Date.valueOf("2008-03-21"); assertTrue(holiday.isHoliday(goodFriday)); Date christmas = java.sql.Date.valueOf("2008-12-25"); assertTrue(holiday.isHoliday(christmas)); Date boxing = java.sql.Date.valueOf("2008-12-26"); assertTrue(holiday.isHoliday(boxing)); Date labour = java.sql.Date.valueOf("2008-10-27"); assertTrue(holiday.isHoliday(labour)); Date notlabour = java.sql.Date.valueOf("2008-10-25"); assertFalse(holiday.isHoliday(notlabour)); }
From source file:com.company.controller.admin.StudentController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String save(HttpServletRequest req) { try {/*from www . ja v a2 s .c om*/ Student s = new Student(); s.setFirstName(req.getParameter("firstName")); s.setLastName(req.getParameter("lastName")); s.setEmail(req.getParameter("email")); s.setGender(req.getParameter("gender")); s.setContactNo(req.getParameter("contactNo")); try { DateFormat dob = new SimpleDateFormat("yyyy-mm-dd"); s.setDob(dob.parse(req.getParameter("dob"))); } catch (ParseException pe) { System.out.println(pe.getMessage()); } s.setStatus(req.getParameter("status") != null); if (req.getParameter("id") != null && req.getParameter("id").equals("0")) { //return s.toString(); studentService.insert(s); } else { s.setId(Integer.parseInt(req.getParameter("id"))); studentService.update(s); } } catch (SQLException se) { return se.getMessage(); } return "redirect:/admin/students"; }
From source file:com.museum_web.controller.MuseologicalController.java
@RequestMapping("actions/saveMuseological") public void save(MuseologicalObject museum, HttpServletRequest request, HttpServletResponse response) throws Exception { //ModelAndView mv = new ModelAndView("museum/list"); String dateText = request.getParameter("dateText"); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Calendar cal = Calendar.getInstance(); cal.setTime(df.parse(dateText)); museum.setDate(cal);/* w w w . j av a 2 s. co m*/ if (museum.getId() == 0) { museum.setId(null); new MuseologicalObjectService().createObject(museum); } else { new MuseologicalObjectService().editObject(museum); } response.sendRedirect("../museological"); }
From source file:th.co.geniustree.intenship.advisor.controller.InformationController.java
@RequestMapping(value = "/searchinformation", method = RequestMethod.POST) private Page<Information> searchInformation(SearchData searchData, Pageable pageable) throws ParseException { String keyword = searchData.getKeyWord(); String searchBy = searchData.getSearchBy(); Page<Information> informations = null; if ("title".equals(searchBy)) { informations = informationSearchService.searchByTitle(keyword, pageable); }/*from w ww . j av a 2 s. co m*/ if ("startTime".equals(searchBy)) { DateFormat sim = new SimpleDateFormat("yyyy-MM-dd", Locale.US); Date date = sim.parse(keyword); informations = informationSearchService.searchByStartTime(date, date, pageable); } return informations; }
From source file:com.mycompany.apsdtask.EMailStoringSevice.java
public Stream<EMail> searcEMail(String from, String subject, String after, String before) throws ParseException { DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date afterDate = (StringUtils.isEmpty(after)) ? df.parse("1984-07-13 00:00:00") : df.parse(after); Date beforeDate = (StringUtils.isEmpty(before)) ? df.parse("2084-07-13 00:00:00") : df.parse(before); Stream<EMail> results;/*from w w w. j a v a 2 s . c o m*/ if (StringUtils.isEmpty(from)) { if (StringUtils.isEmpty(subject)) { results = eMailRepository.findByDate(afterDate, beforeDate); } else { results = eMailRepository.findByDateAndSubject(afterDate, beforeDate, subject); } } else { if (StringUtils.isEmpty(subject)) { results = eMailRepository.findByDateAndAuthor(afterDate, beforeDate, from); } else { results = eMailRepository.findByDateAuthorAndSubject(afterDate, beforeDate, from, subject); } } return results; }
From source file:no.dusken.aranea.admin.editor.CalendarEditor.java
@Override public void setAsText(String string) throws IllegalArgumentException { DateFormat formatter = new SimpleDateFormat(format, new Locale("no")); Date date;//from w w w. j a va 2 s . c o m try { date = formatter.parse(string); } catch (ParseException e) { throw new IllegalArgumentException("Not in right format: " + format); } Calendar cal = new GregorianCalendar(); cal.setTime(date); setValue(cal); }
From source file:ru.tsystems.project.controllers.WebServicesController.java
@RequestMapping(value = "{dateF}/{dateT}", method = RequestMethod.GET) public @ResponseBody List<TicketDTO> getTickets(@PathVariable String dateF, @PathVariable String dateT) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date dateFrom = null, dateTo = null; try {/* w ww . jav a 2 s.c om*/ dateFrom = format.parse(dateF); dateTo = format.parse(dateT); } catch (ParseException ex) { throw new BadRequestException("Invalid parameters"); } List<TicketDTO> result = ticketService.getTickets(dateFrom, dateTo); return result; }
From source file:com.mycompany.apsdtask.SpringDataEMailStoringSevice.java
@Override public Stream<EMail> searchEMail(String from, String subject, String after, String before) throws ParseException { DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date afterDate = (StringUtils.isEmpty(after)) ? df.parse("1984-07-13 00:00:00") : df.parse(after); Date beforeDate = (StringUtils.isEmpty(before)) ? df.parse("2084-07-13 00:00:00") : df.parse(before); Stream<EMail> results;/* w ww. ja va2 s. c o m*/ if (StringUtils.isEmpty(from)) { if (StringUtils.isEmpty(subject)) { results = eMailRepository.findByDate(afterDate, beforeDate); } else { results = eMailRepository.findByDateAndSubject(afterDate, beforeDate, subject); } } else { if (StringUtils.isEmpty(subject)) { results = eMailRepository.findByDateAndAuthor(afterDate, beforeDate, from); } else { results = eMailRepository.findByDateAuthorAndSubject(afterDate, beforeDate, from, subject); } } return results; }