List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:com.alcatel_lucent.nz.wnmsextract.WNMSDataExtractor.java
public static Calendar parseTimestamp(String timestamp) throws java.text.ParseException { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.setTime(df.parse(timestamp)); //jlog.info(">>>>>"+timestamp+"<<<<<<"+df.format(cal.getTime())); return cal;/* www . j av a2 s.co m*/ }
From source file:it.eng.spagobi.tools.downloadFiles.service.DownloadZipAction.java
/** Extract Date from files name that are in format W0301140201.log where date is first March at time 14:02:01 * //w w w. ja va2s . c om * @param fileName * @return * @throws ParseException */ static public Date extractDate(String fileName, String prefix) throws ParseException { // remove prefix //fileName = fileName.substring(1); int prefixToRemove = prefix.length(); fileName = fileName.substring(prefixToRemove); // remove extension // int point=fileName.indexOf('.'); // fileName = fileName.substring(0, point); int dateLenghtToRemove = FILES_DATE_FORMAT.length(); fileName = fileName.substring(0, dateLenghtToRemove); java.text.DateFormat myTimeFormat = new java.text.SimpleDateFormat(FILES_DATE_FORMAT); Date timeFile = myTimeFormat.parse(fileName); return timeFile; }
From source file:controllers.GoogleComputeEngineApplication.java
public static WebSocket<JsonNode> gceOperations() { return new WebSocket<JsonNode>() { public void onReady(final In<JsonNode> in, final Out<JsonNode> out) { final ActorRef computeActor = Akka.system() .actorOf(Props.create(GoogleComputeEngineConnection.class, out)); in.onMessage(new F.Callback<JsonNode>() { @Override/*from ww w . ja v a 2 s .c o m*/ public void invoke(JsonNode jsonNode) throws Throwable { if (jsonNode.has("action") && "retrieve".equals(jsonNode.get("action").textValue())) { Date lastOperationDate = null; if (jsonNode.has("lastOperationDate")) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); try { lastOperationDate = format.parse(jsonNode.get("lastOperationDate").textValue()); } catch (ParseException e) { System.out.println("Date parse error: " + e.getMessage()); } } final ActorRef computeActor = Akka.system() .actorOf(Props.create(GoogleComputeEngineConnection.class, out)); GoogleComputeEngineService.listOperations(computeActor, lastOperationDate); } } }); in.onClose(new F.Callback0() { @Override public void invoke() throws Throwable { Akka.system().stop(computeActor); } }); } }; }
From source file:foam.zizim.android.Util.java
/** * Format date into more readable format. * /* w w w . j av a2 s . com*/ * @param date - the date to be formatted. * @return String */ public static String formatDate(String fromFormat, String date, String toFormat) { String formatted = ""; DateFormat formatter = new SimpleDateFormat(fromFormat, Locale.ENGLISH); try { Date dateStr = formatter.parse(date); formatted = formatter.format(dateStr); Date formatDate = formatter.parse(formatted); formatter = new SimpleDateFormat(toFormat); formatted = formatter.format(formatDate); } catch (ParseException e) { e.printStackTrace(); } return formatted; }
From source file:com.consol.citrus.samples.flightbooking.entity.converter.FlightConverter.java
/** * Get model form entity.// w w w. j a v a 2s. co m * @param entity * @return * @throws ParseException */ public static Flight from(FlightEntity entity) { DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM'T'HH:mm:ss"); if (entity == null) { return null; } Flight model = new Flight(); Calendar scheduledArrival = null; Calendar scheduledDeparture = null; try { if (StringUtils.hasText(entity.getScheduledArrival())) { scheduledArrival = Calendar.getInstance(); scheduledArrival.setTime(dateFormat.parse(entity.getScheduledArrival())); } if (StringUtils.hasText(entity.getScheduledDeparture())) { scheduledDeparture = Calendar.getInstance(); scheduledDeparture.setTime(dateFormat.parse(entity.getScheduledDeparture())); } } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse date format", e); } model.setAirline(entity.getAirline()); model.setFlightId(entity.getFlightId()); model.setFromAirport(entity.getFromAirport()); model.setScheduledArrival(scheduledArrival); model.setToAirport(entity.getToAirport()); model.setScheduledDeparture(scheduledDeparture); return model; }
From source file:com.tascape.qa.th.Utils.java
public static long getTime(String time, String format) throws ParseException { DateFormat formatter = new SimpleDateFormat(format); Date date = formatter.parse(time); return date.getTime(); }
From source file:org.linkedeconomy.espa.service.impl.rdf.ReviewEspaImpl.java
public static void review() throws ParseException { //services for each table ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); ReviewService rev = (ReviewService) ctx.getBean("reviewServiceImpl"); List<Review> review = rev.getReview(); //--------------RDF Model--------------// Model model = ModelFactory.createDefaultModel(); Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); InfModel infModel = ModelFactory.createInfModel(reasoner, model); model.setNsPrefix("elod", OntologySpecification.elodPrefix); model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix); model.setNsPrefix("dcterms", OntologySpecification.dctermsPrefix); //number format DecimalFormat df = new DecimalFormat("0.00"); for (Review review1 : review) { Resource instanceCurrency = infModel.createResource("http://linkedeconomy.org/resource/Currency/EUR"); Resource instanceCountry = infModel.createResource("http://linkedeconomy.org/resource/Country/GR"); Resource instanceBudgetUps = infModel.createResource( OntologySpecification.instancePrefix + "UnitPriceSpecification/BudgetItem/" + review1.getOps()); Resource instanceSpendingUps = infModel.createResource(OntologySpecification.instancePrefix + "UnitPriceSpecification/SpendingItem/" + review1.getOps()); Resource instanceBudget = infModel .createResource(OntologySpecification.instancePrefix + "BudgetItem/" + review1.getOps()); Resource instanceSpending = infModel .createResource(OntologySpecification.instancePrefix + "SpendingItem/" + review1.getOps()); Resource instanceSpendingExpLine = infModel.createResource( OntologySpecification.instancePrefix + "ExpenditureLine/SpendingItem/" + review1.getOps()); Resource instanceProject = infModel .createResource(OntologySpecification.instancePrefix + "Subsidy/" + review1.getOps()); DateFormat dfDate = new SimpleDateFormat("dd/MM/yyyy"); DateFormat dfDate2 = new SimpleDateFormat("yyyy-MM-dd"); DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); java.util.Date stDateStarts; java.util.Date stDateEnds; java.util.Date stDateIssued; stDateStarts = dfDate.parse(review1.getStartDate()); stDateEnds = dfDate.parse(review1.getFinishDate()); stDateIssued = dfDate2.parse(review1.getDate().toString()); String startDate = df2.format(stDateStarts); String endDate = df2.format(stDateEnds); String issuedDate = df2.format(stDateIssued); infModel.add(instanceBudgetUps, RDF.type, OntologySpecification.priceSpecificationResource); infModel.add(instanceSpendingUps, RDF.type, OntologySpecification.priceSpecificationResource); infModel.add(instanceBudget, RDF.type, OntologySpecification.budgetResource); infModel.add(instanceSpending, RDF.type, OntologySpecification.spendingResource); infModel.add(instanceSpendingExpLine, RDF.type, OntologySpecification.expLineResource); infModel.add(instanceProject, RDF.type, OntologySpecification.subsidyResource); instanceProject.addProperty(OntologySpecification.hasRelatedBudgetItem, instanceBudget); model.add(OntologySpecification.subsidyResource, RDFS.subClassOf, OntologySpecification.projectResource); model.add(OntologySpecification.budgetResource, RDFS.subClassOf, OntologySpecification.financialResource); model.add(OntologySpecification.spendingResource, RDFS.subClassOf, OntologySpecification.financialResource); instanceProject.addProperty(OntologySpecification.hasRelatedSpendingItem, instanceSpending); instanceProject.addProperty(OntologySpecification.countryIsoCode, instanceCountry); // instanceBudget.addProperty(OntologySpecification.hasExpenditureLine, instanceBudgetExpLine); instanceSpending.addProperty(OntologySpecification.hasExpenditureLine, instanceSpendingExpLine); instanceBudget.addProperty(OntologySpecification.price, instanceBudgetUps); instanceSpendingExpLine.addProperty(OntologySpecification.amount, instanceSpendingUps); instanceSpendingUps.addProperty(OntologySpecification.hasCurrencyValue, df.format(review1.getSpending()), XSDDatatype.XSDfloat); instanceSpendingUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true", XSDDatatype.XSDboolean); instanceSpendingUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency); instanceBudgetUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency); instanceBudgetUps.addProperty(OntologySpecification.hasCurrencyValue, df.format(review1.getBudget()), XSDDatatype.XSDfloat);/* w w w. j a va2s .c o m*/ instanceBudgetUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true", XSDDatatype.XSDboolean); instanceProject.addProperty(OntologySpecification.desc, String.valueOf(review1.getDescription()), "el"); instanceProject.addProperty(OntologySpecification.title, String.valueOf(review1.getTitle()), "el"); instanceProject.addProperty(OntologySpecification.projectId, String.valueOf(review1.getOps()), XSDDatatype.XSDstring); instanceProject.addProperty(OntologySpecification.issued, issuedDate, XSDDatatype.XSDdateTime); instanceProject.addProperty(OntologySpecification.completion, String.valueOf(review1.getCompletion()), XSDDatatype.XSDfloat); instanceProject.addProperty(OntologySpecification.countOfRelatedProjects, String.valueOf(review1.getSubProjects()), XSDDatatype.XSDstring); instanceProject.addProperty(OntologySpecification.startDate, startDate, XSDDatatype.XSDdateTime); instanceProject.addProperty(OntologySpecification.endDate, endDate, XSDDatatype.XSDdateTime); } try { FileOutputStream fout = new FileOutputStream( "/Users/giovaf/Documents/yds_pilot1/espa_tests/22-02-2016_ouput/reviewEspa.rdf"); model.write(fout); } catch (IOException e) { System.out.println("Exception caught" + e.getMessage()); } }
From source file:edu.temple.cis3238.wiki.utils.StringUtils.java
/** * Formats date string with specified dateformat. * @param dateStr Date to format//from w ww. j av a 2 s. c om * @param formattedDateOut Format string * @return Formatted date */ public static String formatDate(String dateStr, String formattedDateOut) { DateFormat dateformat = new SimpleDateFormat(DEFAULT_SQL_DATETIME_FMT, Locale.ENGLISH); DateFormat dateformatOut = new SimpleDateFormat(formattedDateOut, Locale.ENGLISH); try { return dateformatOut.format(dateformat.parse(dateStr)); } catch (Exception ex) { Logger.getLogger(StringUtils.class.getName()).log(Level.SEVERE, null, ex); } return dateStr; }
From source file:com.twitter.elephanttwin.util.DateUtil.java
/** * Parse date with using given format.// www . j a v a 2 s . c o m * Returns null in case of errors. */ public static Calendar fromString(String dateStr, DateFormat df) { try { return fromDate(df.parse(dateStr)); } catch (ParseException e) { // SUPPRESS CHECKSTYLE string multiple times LOG.warn("Could not parse date " + dateStr + " with dateformat " + df, e); return null; } }
From source file:Main.java
public static Date getDateFromString(String dateString) { DateFormat inputFormat = null; if (dateString == null) { return null; }/*from w ww.j a va 2 s . c o m*/ if (dateString.length() == 19) inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); if (dateString.length() == 10) inputFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); if (inputFormat == null) { return null; } inputFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date parsed = null; try { parsed = inputFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return parsed; }