List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:org.cs.basic.test.util.DateUtils.java
/**? * @param dateTime//from ww w . ja v a 2 s . co m * @return */ public static Date beforeMonth(String dateTime) { Calendar now = Calendar.getInstance(); SimpleDateFormat simpledate = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = simpledate.parse(dateTime); } catch (ParseException ex) { System.out.println("????" + ex.getMessage()); return null; } now.setTime(date); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH) - 1; int day = now.get(Calendar.DAY_OF_MONTH); now.set(year, month, day); return now.getTime(); }
From source file:org.cs.basic.test.util.DateUtils.java
/**? * //from w w w . ja va 2 s .c o m * @param dateTime * @return */ public static Date beforeMonthFristDay(String dateTime) { java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd"); Calendar now = Calendar.getInstance(); Date date = null; try { date = df.parse(dateTime); } catch (ParseException ex) { System.out.println("????" + ex.getMessage()); } now.setTime(date); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH) - 1; int day = now.get(Calendar.DAY_OF_MONTH); now.set(year, month, day); now.set(now.DATE, 1); return now.getTime(); }
From source file:net.sourceforge.fenixedu.presentationTier.backBeans.manager.personManagement.ManagerFunctionsManagementBackingBean.java
@Override public String associateNewFunction() throws FenixServiceException, ParseException { DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Double credits = Double.valueOf(this.getCredits()); Date beginDate_ = null, endDate_ = null; try {// w w w .j a va 2 s. c om if (this.getBeginDate() != null) { beginDate_ = format.parse(this.getBeginDate()); } else { setErrorMessage("error.notBeginDate"); return ""; } if (this.getEndDate() != null) { endDate_ = format.parse(this.getEndDate()); } else { setErrorMessage("error.notEndDate"); return ""; } AssociateNewFunctionToPerson.runAssociateNewFunctionToPerson(this.getFunctionID(), this.getPersonID(), credits, YearMonthDay.fromDateFields(beginDate_), YearMonthDay.fromDateFields(endDate_)); setErrorMessage("message.success"); return "success"; } catch (ParseException e) { setErrorMessage("error.date1.format"); } catch (FenixServiceException e) { setErrorMessage(e.getMessage()); } catch (DomainException e) { setErrorMessage(e.getMessage()); } return ""; }
From source file:se.vgregion.services.calendar.CalendarServiceImpl.java
@Override public CalendarEvents getCalendarEventsFromIcalUrl(String url, CalendarEventsPeriod period, String type) throws CalendarServiceException { CalendarEvents calendarEvents = new CalendarEvents(); calendarEvents.setCalendarItems(new ArrayList<CalendarItem>()); Interval queryInterval = new Interval(period.getStartDate(), period.getEndDate()); try {// w w w .ja v a 2 s .c o m Calendar calendar = parseIcalUrl(url); Iterator<VEvent> itr = calendar.getComponents(Component.VEVENT).iterator(); while (itr.hasNext()) { VEvent vEvent = itr.next(); Date startDate = vEvent.getStartDate().getDate(); Date endDate = vEvent.getEndDate().getDate(); boolean wholeDays = !(startDate instanceof net.fortuna.ical4j.model.DateTime); if (wholeDays) { // Whole day event. Have had timezone problems with whole day events. Workaround it. String datePartStart = startDate.toString(); String datePartEnd = endDate.toString(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); sdf.setTimeZone(TimeZone.getDefault()); try { java.util.Date startParsed = sdf.parse(datePartStart); java.util.Date endParsed = sdf.parse(datePartEnd); startDate = new net.fortuna.ical4j.model.DateTime(startParsed); // Subtract a millisecond so we don't regard the event as taking place on the next day. Now we // end the event one millisecond before the day turns. endDate = new net.fortuna.ical4j.model.DateTime(endParsed.getTime() - 1); } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } } Interval interval = new Interval(startDate.getTime(), endDate.getTime()); if (interval.overlaps(queryInterval)) { CalendarItem item = new CalendarItem(); item.setInterval(interval); item.setTitle(vEvent.getSummary().getValue()); item.setCalendarType(type); item.setWholeDays(wholeDays); calendarEvents.getCalendarItems().add(item); } } } catch (IOException ioe) { throw new CalendarServiceException(ioe); } catch (ParserException pe) { throw new CalendarServiceException(pe); } return calendarEvents; }
From source file:io.fabric8.maven.core.service.openshift.ImageStreamService.java
private Date extractDate(TagEvent tag) { try {//from w ww . j av a 2 s. c o m return new SimpleDateFormat(DATE_FORMAT).parse(tag.getCreated()); } catch (ParseException e) { log.error("parsing date error : " + e.getMessage(), e); return null; } catch (NullPointerException e) { log.error("tag date is null : " + e.getMessage(), e); return null; } }
From source file:org.cs.basic.test.util.DateUtils.java
/**?? * /*from w ww . jav a 2 s . c o m*/ * @param dateTime * @return */ public static Date beforeMonthLastDay(String dateTime) { Calendar now = Calendar.getInstance(); java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = df.parse(dateTime); } catch (ParseException ex) { System.out.println("????" + ex.getMessage()); } now.setTime(date); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH) - 1; int day = now.get(Calendar.DAY_OF_MONTH); now.set(year, month, day); // ?1? now.add(now.MONTH, 1); // 1??zhii now.set(now.DATE, 1); // 1????? now.add(now.DATE, -1); return now.getTime(); }
From source file:org.cs.basic.test.util.DateUtils.java
/**?? * @param dateTime/*from ww w . j a v a 2 s .c o m*/ * @return */ public static Date monthLastDay(String dateTime) { Calendar now = Calendar.getInstance(); java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = df.parse(dateTime); } catch (ParseException ex) { System.out.println("????" + ex.getMessage()); } now.setTime(date); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH); int day = now.get(Calendar.DAY_OF_MONTH); now.set(year, month, day); // ?1? now.add(now.MONTH, 1); // 1??zhii now.set(now.DATE, 1); // 1????? now.add(now.DATE, -1); return now.getTime(); }
From source file:model.manager.SearchManager.java
public static List<PatientIdentifier> getPatientIdentifiersByName(Session session, String patientId, boolean includeInactivePatients, List<IdentifierType> types) throws HibernateException { String jsonString;/*from w w w.j a v a 2 s.c o m*/ String[] resourceArray; String nid; Date theDate; Date _theDate; List<PatientIdentifier> patientIdentifiers = new ArrayList<PatientIdentifier>(); RestClient restClient = new RestClient(); String resource = restClient.getOpenMRSResource("patient?q=" + StringUtils.replace(patientId, " ", "%20")); String _resource = (String) resource.subSequence(11, resource.length()); _resource = _resource.substring(0, _resource.length() - 1); JSONArray jsonArray = new JSONArray(_resource); for (int i = 0; i < JsonHelper.toList(jsonArray).size(); i++) { PatientIdentifier identifier = new PatientIdentifier(); patient = new Patient(); jsonString = JsonHelper.toList(jsonArray).get(i).toString().replaceAll("display=", "") .replaceAll("uuid=", ""); jsonString = jsonString.substring(1, jsonString.length() - 1); resourceArray = jsonString.split(iDartProperties.ARRAY_SPLIT); String nameNid = (resourceArray[0].replaceAll(resourceArray[0].substring(0, 18), " ")).trim(); List<String> fullName = RestUtils.splitName(nameNid); patient.setFirstNames((fullName.get(0) + iDartProperties.SPACE + fullName.get(1)) .replaceAll(iDartProperties.HIFEN, iDartProperties.SPACE).trim()); patient.setLastname(fullName.get(2).replaceAll("-", " ").trim()); nid = restClient.getOpenMRSResource(iDartProperties.REST_GET_PATIENT_GENERIC + resourceArray[3].trim()); JSONObject jsonObject = new JSONObject(nid); nid = String.valueOf(jsonObject.get("display")); nid = nid.substring(0, nid.indexOf("-")).trim(); String strBirthdate = jsonObject.getJSONObject("person").getString("birthdate"); char gender = jsonObject.getJSONObject("person").getString("gender").charAt(0); String year = strBirthdate.substring(0, 4); String month = new DateFormatSymbols(Locale.ENGLISH) .getMonths()[Integer.valueOf(strBirthdate.substring(5, 7)) - 1]; Integer day = Integer.valueOf(strBirthdate.substring(8, 10)); SimpleDateFormat _sdf = new SimpleDateFormat("d-MMMM-yyyy", Locale.ENGLISH); String dataInicioTarv = restClient.getOpenMRSResource(iDartProperties.REST_OBS_PATIENT + resourceArray[3].trim() + iDartProperties.CONCEPT_DATA_INICIO_TARV); if (dataInicioTarv.length() > 14) { dataInicioTarv = dataInicioTarv.substring(94); dataInicioTarv = dataInicioTarv.substring(0, 10); String _year = dataInicioTarv.substring(6, 10); String _month = new DateFormatSymbols(Locale.ENGLISH) .getMonths()[Integer.valueOf(dataInicioTarv.substring(3, 5)) - 1]; Integer _day = Integer.valueOf(dataInicioTarv.substring(0, 2)); _theDate = null;//Data de Inicio Tarv try { _theDate = _sdf.parse(_day.toString() + "-" + _month + "-" + _year); } catch (ParseException e1) { System.out.println(e1.getMessage()); } patient.setAttributeValue(PatientAttribute.ARV_START_DATE, _theDate); } SimpleDateFormat sdf = new SimpleDateFormat("d-MMMM-yyyy", Locale.ENGLISH); theDate = null;//Data de Nascimento try { theDate = sdf.parse(day.toString() + "-" + month + "-" + year); } catch (ParseException e1) { System.out.println(e1.getMessage()); } patient.setDateOfBirth(theDate); patient.setPatientId(nid); patient.setSex(gender); identifier.setType(types.get(0)); identifier.setValueEdit(null); identifier.setValue(nid); identifier.setPatient(patient); patientIdentifiers.add(identifier); } return patientIdentifiers; }
From source file:com.sinet.gage.delta.DomainUpdatesImporter.java
private Date getDateFormat(String date) { Date formattedDate = null;/*from ww w.j a v a 2 s. c o m*/ try { if (date != null) { formattedDate = new Date(dateFormat.parse(date).getTime()); } } catch (ParseException e) { log.error("Invalid date format: " + e.getMessage()); } return formattedDate; }
From source file:com.salesforce.marketingcloud.android.demoapp.LearningAppApplication.java
@Override public NotificationCompat.Builder setupNotificationBuilder(@NonNull Context context, @NonNull NotificationMessage notificationMessage) { NotificationCompat.Builder builder = NotificationManager.getDefaultNotificationBuilder(context, notificationMessage, NotificationManager.createDefaultNotificationChannel(context), R.drawable.ic_stat_app_logo_transparent); Map<String, String> customKeys = notificationMessage.customKeys(); if (!customKeys.containsKey("category") || !customKeys.containsKey("sale_date")) { return builder; }/* ww w.j a v a2 s . c o m*/ if ("sale".equalsIgnoreCase(customKeys.get("category"))) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); simpleDateFormat.setTimeZone(TimeZone.getDefault()); try { Date saleDate = simpleDateFormat.parse(customKeys.get("sale_date")); Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, saleDate.getTime()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, saleDate.getTime()) .putExtra(CalendarContract.Events.TITLE, customKeys.get("event_title")) .putExtra(CalendarContract.Events.DESCRIPTION, customKeys.get("alert")) .putExtra(CalendarContract.Events.HAS_ALARM, 1) .putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true); PendingIntent pendingIntent = PendingIntent.getActivity(context, R.id.interactive_notification_reminder, intent, PendingIntent.FLAG_CANCEL_CURRENT); builder.addAction(android.R.drawable.ic_menu_my_calendar, getString(R.string.in_btn_add_reminder), pendingIntent); } catch (ParseException e) { Log.e(TAG, e.getMessage(), e); } } return builder; }