Example usage for java.text DateFormat parse

List of usage examples for java.text DateFormat parse

Introduction

In this page you can find the example usage for java.text DateFormat parse.

Prototype

public Date parse(String source) throws ParseException 

Source Link

Document

Parses text from the beginning of the given string to produce a date.

Usage

From source file:org.openmrs.module.patientportaltoolkit.fragment.controller.AppointmentsFragmentController.java

public void markCompleted(FragmentModel model,
        @RequestParam(value = "reminderId", required = true) String reminderId,
        @RequestParam(value = "markCompletedDate", required = true) String markCompletedDate,
        @RequestParam(value = "doctorName", required = true) String doctorName,
        @RequestParam(value = "comments", required = true) String comments, PageRequest pageRequest) {

    Person person = Context.getPersonService().getPerson(
            Context.getService(ReminderService.class).getRemindersById(reminderId).getPatient().getPersonId());
    log.info(PPTLogAppender.appendLog("MARK_COMPLETED_APPOINTMENTS", pageRequest.getRequest()));
    // log.info("~MARK_COMPLETED_APPOINTMENTS~"+ Context.getAuthenticatedUser().getUsername()+ "~REQ_FOR:"+ Context.getUserService().getUsersByPerson(person,false).get(0).getUsername());
    //System.out.println("121212121212"+markCompletedDate);
    DateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
    Date date = new Date();
    try {//from w w w  .j av a2s . c  om
        date = format.parse(markCompletedDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Context.getService(ReminderService.class).markCompletedReminder(reminderId, date, doctorName, comments);

}

From source file:hello.Scraper.java

@Transformer(inputChannel = "channel3", outputChannel = "channel4")
public DumpEntry convert(Element payload) throws ParseException {
    String dateStr = payload.ownText().substring(0, 19);

    DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    format.setTimeZone(TimeZone.getTimeZone("GMT"));

    Date timestamp = format.parse(dateStr);

    Elements list = payload.select("a");
    String id;/*  w  w w. j av  a2 s. c  o  m*/
    String ref;
    if (list.size() > 0) {
        Element a = list.get(0);
        id = a.ownText();
        ref = a.attr("href");
    } else {
        id = "private data";
        ref = null;
    }

    Element span = payload.select("span").get(0);
    String status = span.ownText();

    return new DumpEntry(timestamp, id, ref, status);
}

From source file:th.co.geniustree.dental.controller.PriceAndExpireProductController.java

@RequestMapping(value = "/loadpriceandexpireproduct/searchpriceandexpireproduct", method = RequestMethod.POST)
public Page<PriceAndExpireProduct> searchPriceAndExpireProduct(@RequestBody SearchData searchData,
        Pageable pageable) throws ParseException {
    String keyword = searchData.getKeyword();
    String searchBy = searchData.getSearchBy();
    Page<PriceAndExpireProduct> priceAndExpireProducts = null;
    DateFormat df = new SimpleDateFormat("yyy-MM-dd", Locale.US);
    if ("LotIn".equals(searchBy)) {
        Date keywordDate = df.parse(keyword);
        priceAndExpireProducts = priceAndExpireProductService.searchByLot(keywordDate, pageable);
    }//from ww w .ja  v  a  2 s  .  c  om
    if ("NameProduct".equals(searchBy)) {
        priceAndExpireProducts = priceAndExpireProductService.searchByProduct(keyword, pageable);
    }
    if ("Expire".equals(searchBy)) {
        Date keywordDate = df.parse(keyword);
        priceAndExpireProducts = priceAndExpireProductService.searchByExpire(keywordDate, pageable);
    }
    return priceAndExpireProducts;
}

From source file:th.co.geniustree.dental.controller.PriceAndExpireProductController.java

@RequestMapping(value = "/countsearchpriceandexpireproduct", method = RequestMethod.POST)
public long countSearchPriceAndExpireProduct(@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 ("LotIn".equals(searchBy)) {
        Date keywordDate = df.parse(keyword);
        count = priceAndExpireProductRepo.count(PriceAndExpireProductSpec.lotInBetween(keywordDate));
    }/* w  ww.  ja  va  2  s.  c  om*/
    if ("NameProduct".equals(searchBy)) {
        count = priceAndExpireProductRepo.count(PriceAndExpireProductSpec.productLike("%" + keyword + "%"));
    }
    if ("Expire".equals(searchBy)) {
        Date keywordDate = df.parse(keyword);
        count = priceAndExpireProductRepo.count(PriceAndExpireProductSpec.expireBetween(keywordDate));
    }
    return count;
}

From source file:com.taobao.itest.util.DateConverter.java

protected Object convertToDate(@SuppressWarnings("rawtypes") Class type, Object value) {
    if (value instanceof String) {
        try {// w  ww  . j  a v a2  s  .  c om
            if (StringUtils.isEmpty(value.toString())) {
                return null;
            }
            String pattern = getDatePattern();
            if (value.toString().contains(":")) {
                pattern = getDateTimePattern();
            }
            DateFormat df = new SimpleDateFormat(pattern);
            Date date = df.parse((String) value);
            if (type.equals(Timestamp.class)) {
                return new Timestamp(date.getTime());
            }
            return date;
        } catch (Exception pe) {
            pe.printStackTrace();
            throw new ConversionException("Error converting String to Date");
        }
    } else if (value instanceof Date) {
        return value;
    } else if (value instanceof Long) {
        return getGmtDate((Long) value);
    }

    throw new ConversionException("Could not convert " + value.getClass().getName() + " to " + type.getName());
}

From source file:th.co.geniustree.dental.controller.AppointmentController.java

@RequestMapping(value = "/countsearchappointment", method = RequestMethod.POST)
private long countSearchAppointment(@RequestBody SearchData searchData) throws ParseException {
    String keyword = searchData.getKeyword();
    String searchBy = searchData.getSearchBy();
    long count = 0;
    if ("".equals(searchBy)) {
        count = appointmentRepo.count(AppointmentSpec.namePatientLike("%" + keyword + "%"));
    }//from  www  . ja v  a 2s  .co m
    if ("".equals(searchBy)) {
        count = appointmentRepo.count(AppointmentSpec.nameDoctorLike("%" + keyword + "%"));
    }
    if ("".equals(searchBy)) {
        count = appointmentRepo.count(AppointmentSpec.mobileLike("%" + keyword + "%"));
    }
    if ("".equals(searchBy)) {
        DateFormat sim = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        Date date = sim.parse(keyword);
        count = appointmentRepo.count(AppointmentSpec.appointmentDate(date));
    }
    return count;
}

From source file:th.co.geniustree.dental.controller.AppointmentController.java

@RequestMapping(value = "/searchappointment", method = RequestMethod.POST)
private Page<Appointment> searchAppointment(@RequestBody SearchData searchData, Pageable pageable)
        throws ParseException {
    Page<Appointment> appointments = null;
    String ketyword = searchData.getKeyword();
    String searchBy = searchData.getSearchBy();
    if ("".equals(searchBy)) {
        appointments = appointmentService.searchByPatientName(ketyword, pageable);
    }/*from  w w w  .jav  a  2s.  c  o m*/
    if ("".equals(searchBy)) {
        appointments = appointmentService.searchByDoctorName(ketyword, pageable);
    }
    if ("".equals(searchBy)) {
        appointments = appointmentService.searchByMobile(ketyword, pageable);
    }
    if ("".equals(searchBy)) {
        DateFormat sim = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        Date date = sim.parse(ketyword);
        appointments = appointmentService.searchByAppointmentDay(date, pageable);
    }
    return appointments;
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 * date1?date2?date1date2true date1date2?2009-08-01
 *///w  w  w .  j a v a  2 s .  c  o m
public static boolean isDate10Before(String date1, String date2) {
    try {
        DateFormat df = DateFormat.getDateInstance();
        return df.parse(date1).before(df.parse(date2));
    } catch (ParseException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.education.lessons.ui.server.login.AbstractLoginController.java

protected User extractUser(HttpServletRequest request) {
    String email = str(request.getParameter("email"));
    String nickname = str(request.getParameter("nickname"));
    String password = str(request.getParameter("password"));
    String fullname = str(request.getParameter("fullname"));
    String gender = str(request.getParameter("gender"));
    String birthday = str(request.getParameter("birthday"));
    String country = str(request.getParameter("country"));
    String language = str(request.getParameter("language"));
    String postcode = str(request.getParameter("postcode"));
    String timezone = str(request.getParameter("timezone"));

    if (email == null) {
        throw new WebException(AbstractLoginController.class.getName() + ".email.empty");
    }/*ww w .  j a  va 2  s . c om*/

    if (nickname == null) {
        throw new WebException(AbstractLoginController.class.getName() + ".nickname.empty");
    }

    if (password == null) {
        throw new WebException(AbstractLoginController.class.getName() + ".password.empty");
    }

    User user = new User();
    user.setEmail(email);
    user.setNickname(nickname);
    user.setPassword(password);
    user.setFullname(fullname);

    if (gender != null) {
        user.setGender(Gender.valueOf(gender));
    }

    if (birthday != null) {
        try {
            DateFormat format = new SimpleDateFormat("dd/MM/yyyy");
            user.setBirthday(format.parse(birthday));
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    if (country != null) {
        user.setCountry(loginService.findCountryByCode(country));
    }

    if (language != null) {
        user.setLanguage(loginService.findLanguageByCode(language));
    }

    user.setPostcode(postcode);
    user.setTimezone(timezone);
    return user;
}

From source file:th.co.geniustree.dental.controller.DetailHealController.java

@RequestMapping(value = "/loaddetailheal/searchdetailheal", method = RequestMethod.POST)
public Page<DetailHeal> search(@RequestBody SearchData searchData, Pageable pageable) throws ParseException {
    String keyword = searchData.getKeyword();
    String searchBy = searchData.getSearchBy();
    Page<DetailHeal> detailHeals = null;
    if ("".equals(searchBy)) {
        detailHeals = detailHealService.searchByPatient(keyword, pageable);
    }//ww w.  ja  va  2 s . c  o  m
    if ("".equals(searchBy)) {
        detailHeals = detailHealService.searchByDoctor(keyword, pageable);
    }
    if ("?".equals(searchBy)) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        Date keywordDate = df.parse(keyword);
        detailHeals = detailHealService.searchByDateHeal(keywordDate, pageable);
    }
    return detailHeals;
}