List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:de.perdian.commons.lang.conversion.impl.converters.TestDateToStringConverter.java
@Test public void testConvertWithFormat() throws ParseException { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DateToStringConverter converter = new DateToStringConverter(dateFormat); Assert.assertEquals("2012-02-08 12:34:56", converter.convert(dateFormat.parse("2012-02-08 12:34:56"))); }
From source file:com.eryansky.common.utils.DateUtil.java
/** * /*from ww w. j a v a 2s . com*/ * ??? ? 2008-08-08 16:16:34 */ public static String addHours(String startDate, int intHour) { try { DateFormat df = DateFormat.getDateTimeInstance(); Date date = df.parse(startDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); long longMills = cal.getTimeInMillis() + intHour * 60 * 60 * 1000; cal.setTimeInMillis(longMills); // return df.format(cal.getTime()); } catch (Exception Exp) { return null; } }
From source file:com.eryansky.common.utils.DateUtil.java
/** * /* www . j a v a 2 s. c om*/ * ???? ? 2008-08-08 16:16:34 */ public static String delHours(String startDate, int intHour) { try { DateFormat df = DateFormat.getDateTimeInstance(); Date date = df.parse(startDate); Calendar cal = Calendar.getInstance(); cal.setTime(date); long longMills = cal.getTimeInMillis() - intHour * 60 * 60 * 1000; cal.setTimeInMillis(longMills); // return df.format(cal.getTime()); } catch (Exception Exp) { return null; } }
From source file:io.seldon.importer.articles.dynamicextractors.FirstElementTextValueDateDynamicExtractor.java
@Override public String extract(AttributeDetail attributeDetail, String url, Document articleDoc) throws Exception { String attrib_value = null;//from www .j a v a 2s. c o m if ((attributeDetail.extractor_args != null) && (attributeDetail.extractor_args.size() >= 1)) { String cssSelector = attributeDetail.extractor_args.get(0); Element element = articleDoc.select(cssSelector).first(); if (StringUtils.isNotBlank(cssSelector)) { if (element != null) { attrib_value = element.text(); } } } if (attrib_value != null) { String pubtext = attrib_value; SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DateFormat df = new SimpleDateFormat("dd/mm/yyyy hh:mm", Locale.ENGLISH); Date result = null; try { result = df.parse(pubtext); } catch (ParseException e) { logger.info("Failed to parse date withUTC format " + pubtext); } // try a simpler format df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); try { result = df.parse(pubtext); } catch (ParseException e) { logger.info("Failed to parse date " + pubtext); } if (result != null) { attrib_value = dateFormatter.format(result); } else { logger.error("Failed to parse date " + pubtext); } } return attrib_value; }
From source file:com.eryansky.common.utils.DateUtil.java
public static boolean isDateBefore(String date2) { try {/*from w w w . ja v a 2 s . c o m*/ Date date1 = new Date(); DateFormat df = DateFormat.getDateTimeInstance(); return date1.before(df.parse(date2)); } catch (ParseException e) { System.out.print("[SYS] " + e.getMessage()); return false; } }
From source file:controller.ISAuth.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); try (PrintWriter out = response.getWriter()) { String token = request.getParameter("token"); String sql = "SELECT * FROM token WHERE access_token = ?"; JSONObject object = new JSONObject(); try (PreparedStatement statement = conn.prepareStatement(sql)) { statement.setString(1, token); ResultSet result = statement.executeQuery(); if (result.next()) { Date now = new Date(); DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date expiry_date = format.parse(result.getString("expiry_date")); if (now.after(expiry_date)) { object.put("error", "Expired Token"); String deleteQuery = "DELETE FROM token WHERE access_token = ?"; try (PreparedStatement deleteStatement = conn.prepareStatement(deleteQuery)) { deleteStatement.setString(1, token); deleteStatement.execute(); }/*from ww w. j av a2s. c om*/ } else { object.put("id", result.getInt("u_id")); } } catch (SQLException | ParseException e) { } } } catch (SQLException e) { } out.println(object.toString()); } }
From source file:org.openmrs.module.dataintegrityworkflow.web.controller.ViewAssignedRecordsFormController.java
protected Map referenceData(HttpServletRequest req) throws Exception { String assignee = req.getParameter("assignee"); String checkId = req.getParameter("checkId"); String fromDate = req.getParameter("fromDate"); String toDate = req.getParameter("toDate"); String stage = req.getParameter("stage"); String status = req.getParameter("status"); Map<String, Object> modelMap = new HashMap<String, Object>(); User user;//from w ww . j a v a 2s. c o m List<IntegrityWorkflowRecord> records = null; if (assignee != null) { user = Context.getUserService().getUserByUsername(assignee); modelMap.put("assignedUser", user); } else { user = Context.getAuthenticatedUser(); } DataIntegrityWorkflowService dataIntegrityWorkflowService = getDataIntegrityWorkflowService(); if (checkId == null) { records = dataIntegrityWorkflowService.getAssignedIntegrityWorkflowRecordsOfCurrentUser(user); } else if (checkId != null && fromDate != null && toDate != null && status != null && stage != null) { DateFormat formatter; Date fromDateFormatted; Date toDateFormatted; formatter = new SimpleDateFormat("dd/MM/yy"); fromDateFormatted = formatter.parse(fromDate); toDateFormatted = formatter.parse(toDate); records = dataIntegrityWorkflowService.getResultsForCustomQuery(status, stage, fromDateFormatted, toDateFormatted, user, checkId); } else { records = dataIntegrityWorkflowService .getAssignedIntegrityWorkflowRecordsOfSpecifiedCheckAndCurrentUser(user, Integer.parseInt(checkId)); modelMap.put("check", dataIntegrityWorkflowService.getIntegrityCheck(Integer.parseInt(checkId))); } modelMap.put("records", records); return modelMap; }
From source file:de.perdian.apps.dashboard.services.jira.JiraServiceImpl.java
private OverviewDto loadOverview(String rapidViewId, String sprintId, String sprintTitle, JsonClient jsonClient) {// w w w . java 2s . co m StringBuilder sprintReportRequest = new StringBuilder(); sprintReportRequest.append(this.getPropertiesService().getProperty(JiraProperties.ENVIRONMENT_KEY_URL)); sprintReportRequest.append("rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=") .append(rapidViewId); sprintReportRequest.append("&sprintId=").append(sprintId); JsonNode sprintReportNode = jsonClient.sendRequest(sprintReportRequest); OverviewDto overviewDto = new OverviewDto(); overviewDto.setSprintId(sprintId); overviewDto.setSprintTitle(sprintTitle); JsonNode sprintNode = sprintReportNode.get("sprint"); DateFormat sprintDateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); try { overviewDto.setStartDate(sprintDateFormat.parse(sprintNode.get("startDate").asText())); overviewDto.setEndDate(sprintDateFormat.parse(sprintNode.get("endDate").asText())); overviewDto.setCurrentDate(new Date()); } catch (ParseException e) { log.warn("Invalid date format retrieved from JIRA", e); } return overviewDto; }
From source file:com.lushapp.common.utils.DateUtil.java
@SuppressWarnings("unchecked") public static <T extends Date> T parse(String dateString, String dateFormat, Class<T> targetResultType) { if (StringUtils.isEmpty(dateString)) return null; DateFormat df = new SimpleDateFormat(dateFormat); try {// w w w. j a v a 2s. com long time = df.parse(dateString).getTime(); Date t = targetResultType.getConstructor(long.class).newInstance(time); return (T) t; } catch (ParseException e) { String errorInfo = "cannot use dateformat:" + dateFormat + " parse datestring:" + dateString; throw new IllegalArgumentException(errorInfo, e); } catch (Exception e) { throw new IllegalArgumentException("error targetResultType:" + targetResultType.getName(), e); } }