List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:damo.three.ie.util.DateUtils.java
License:Open Source License
/** * Convert a date as {@link String} to milliseconds as {@link Long}. * * @param input Date as String/*from w ww.j a v a 2 s . c o m*/ * @return Date object from inputted string. */ public static Long parseDate(String input) { if (input.equals("Today")) { return Calendar.getInstance().getTime().getTime(); } else if (input.equals("Won't expire**")) { return WONT_EXPIRE; } else if (input.equals("In queue")) { return QUEUED; } else if (input.equals("Expired")) { // for some reason people get usages with expire date of "Expired" // it will be filtered out later. return ALREADY_EXPIRED; } else { DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yy").withLocale(Locale.UK); DateTime dt = formatter.parseDateTime(input.replace("Expires ", "")); return dt.getMillis(); } }
From source file:damo.three.ie.util.DateUtils.java
License:Open Source License
/** * Converts an Out of Bundle date as string to {@link Long} * * @param outOfBundleDate Out of Bundle date * @return Out of bundle date as {@link Long} *///from w w w. j ava2s. co m public static Long parseOutOfBundleDate(String outOfBundleDate) { DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMMMM yyyy").withLocale(Locale.UK); DateTime dt = formatter.parseDateTime(outOfBundleDate); return dt.getMillis(); }
From source file:DAO.FlightDAO.java
public DateTime getDateTimeFromString(String dateString) { if (dateString.isEmpty()) { return DateTime.now(); }//from ww w . j a va 2s . com org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm"); DateTime dt = formatter.parseDateTime(dateString); return dt; }
From source file:DAO.FlightDAO.java
public DateTime getDateTimeFromString2(String dateString) { if (dateString.isEmpty()) { return DateTime.now(); }//from ww w.j a v a 2 s. c om org.joda.time.format.DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss"); DateTime dt = formatter.parseDateTime(dateString); return dt; }
From source file:ddf.metrics.reporting.internal.rest.MetricsEndpoint.java
License:Open Source License
/** * Parse date in ISO8601 format into seconds since Unix epoch. * * @param date/*from w w w . ja va 2 s . c o m*/ * @return */ protected long parseDate(String date) { DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTimeNoMillis(); Date formattedDate = dateFormatter.parseDateTime(date).toDate(); return formattedDate.getTime() / 1000; }
From source file:de.topobyte.osm4j.xml.dynsax.DateParser.java
License:Open Source License
public DateTime parse(String formattedDate) { try {// w w w . j a v a 2s .c om return current.parseDateTime(formattedDate); } catch (IllegalArgumentException e) { // try other parsers } for (int i = 0; i < PARSERS.length; i++) { DateTimeFormatter parser = PARSERS[i]; if (parser == current) { continue; } try { DateTime result = parser.parseDateTime(formattedDate); current = parser; return result; } catch (IllegalArgumentException e) { // continue with next pattern } } throw new RuntimeException("Unable to parse date '" + formattedDate + "'"); }
From source file:de.zib.gndms.dspace.service.SubspaceServiceImpl.java
License:Apache License
@Override @RequestMapping(value = "/_{subspaceId}/_{sliceKindId}", method = RequestMethod.POST) @Secured("ROLE_USER") public ResponseEntity<Specifier<Void>> createSlice(@PathVariable final String subspaceId, @PathVariable final String sliceKindId, @RequestBody final String config, @RequestHeader("DN") final String dn) { GNDMSResponseHeader headers = getSliceKindHeaders(subspaceId, sliceKindId, dn); SliceKind sliceKind;//from w ww . ja va 2s.co m try { sliceKind = slicekindProvider.get(subspaceId, sliceKindId); } catch (NoSuchElementException e) { logger.warn("Tried to access non existing SliceKind " + subspaceId + "/" + sliceKindId, e); return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.NOT_FOUND); } try { Map<String, String> parameters = new HashMap<String, String>(); ParameterTools.parseParameters(parameters, config, null); DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser(); DateTime terminationTime; long sliceSize; if (parameters.containsKey(SliceConfiguration.TERMINATION_TIME)) terminationTime = fmt.parseDateTime(parameters.get(SliceConfiguration.TERMINATION_TIME)); else terminationTime = new DateTime().plus(sliceKind.getDefaultTimeToLive()); if (parameters.containsKey(SliceConfiguration.SLICE_SIZE)) sliceSize = Long.parseLong(parameters.get(SliceConfiguration.SLICE_SIZE)); else sliceSize = sliceKind.getDefaultTimeToLive(); // use provider to create slice String slice = sliceProvider.createSlice(subspaceId, sliceKindId, dn, terminationTime, sliceSize); subspaceProvider.invalidate(subspaceId); // generate specifier and return it Specifier<Void> spec = new Specifier<Void>(); HashMap<String, String> urimap = new HashMap<String, String>(2); urimap.put(UriFactory.SERVICE, "dspace"); urimap.put(UriFactory.SUBSPACE, subspaceId); urimap.put(UriFactory.SLICE_KIND, sliceKindId); urimap.put(UriFactory.SLICE, slice); urimap.put(UriFactory.BASE_URL, baseUrl); spec.setUriMap(new HashMap<String, String>(urimap)); spec.setUrl(uriFactory.sliceUri(urimap, null)); return new ResponseEntity<Specifier<Void>>(spec, headers, HttpStatus.CREATED); } catch (WrongConfigurationException e) { logger.warn(e.getMessage()); return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.BAD_REQUEST); } catch (NoSuchElementException e) { logger.warn(e.getMessage()); return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.NOT_FOUND); } catch (ParameterTools.ParameterParseException e) { logger.info("Illegal request: Could not parse paramter string \"" + ParameterTools.escape(config) + "\". " + e.getMessage()); return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.BAD_REQUEST); } }
From source file:eafit.cdei.asignacion.input.Ejemplo.java
/** * @param args the command line arguments *///from w w w . j a v a2 s .co m public static void main(String[] args) { LocalDate mondayDate = LocalDate.parse("2014-10-20"); String tmpDay = mondayDate.toString("EEEE"); DateTimeFormatter date = DateTimeFormat.forPattern("yyyy-mm-dd"); DateTimeFormatter time = DateTimeFormat.forPattern("hh:mm:ss"); String day = date.parseDateTime("2015-04-16").dayOfWeek().getAsText(); System.out.println(tmpDay + "/" + day); }
From source file:easycare.alc.cuke.steps.esignature.SignInterpretationSteps.java
private void changePatientDetails(HstPatient patient, DataTable dataTable) { CukeMap map = CukeMap.toCukeMap(dataTable); String id = map.get("Id"); String firstName = map.get("First Name"); String lastName = map.get("Last Name"); DateTimeFormatter formatter = messageSource.getDateTimeFormatter(); LocalDate dob = formatter.parseDateTime(map.get("DOB")).toLocalDate(); String gender = map.get("Gender"); String bmi = map.get("bmi"); patient.setFirstName(firstName);/*from w ww . j a va2 s . c om*/ patient.setLastName(lastName); patient.setGender(Gender.valueOf(gender.toUpperCase())); patient.setDob(dob); patient.setBmi(Double.valueOf(bmi)); hstPatientRepository.save(patient); }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission.java
License:Open Source License
/** * need to generate something like// ww w . j a v a 2s. c o m * "2008-03-14T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> */ public Literal getDateTime(Map<String, String[]> queryParameters, String fieldName) { DateTime dt = null; List<String> year = Arrays.asList(queryParameters.get("year" + fieldName)); List<String> month = Arrays.asList(queryParameters.get("month" + fieldName)); List<String> day = Arrays.asList(queryParameters.get("day" + fieldName)); List<String> hour = Arrays.asList(queryParameters.get("hour" + fieldName)); List<String> minute = Arrays.asList(queryParameters.get("minute" + fieldName)); if (year == null || year.size() == 0 || month == null || month.size() == 0 || day == null || day.size() == 0 || hour == null || hour.size() == 0 || minute == null || minute.size() == 0) { //log.info("Could not find query parameter values for date field " + fieldName ); } /* else if( year.size() > 1 || month.size() > 1 || day.size() > 1 || hour.size() > 1 || minute.size() > 1 ){ log.info("Cannot yet handle multiple values for the same field "); } */ String yearParamStr = year.get(0); String monthParamStr = month.get(0); String dayParamStr = day.get(0); String hourParamStr = hour.get(0); String minuteParamStr = minute.get(0); // if all fields are blank, just return a null value if (yearParamStr.length() == 0 && monthParamStr.length() == 0 && dayParamStr.length() == 0 && hourParamStr.length() == 0 && minuteParamStr.length() == 0) { return null; } DateTimeFormatter dateFmt = DateTimeFormat.forPattern("yyyyMMdd:HH:mm"); try { dt = dateFmt.parseDateTime( yearParamStr + monthParamStr + dayParamStr + ':' + hourParamStr + ':' + minuteParamStr); String dateStr = dformater.print(dt); return new EditLiteral(dateStr, DATE_TIME_URI, null); } catch (IllegalFieldValueException ifve) { validationErrors.put(fieldName, ifve.getLocalizedMessage()); return null; } }