List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:cn.loveapple.service.util.DateUtil.java
/** * ???//from ww w.j av a 2 s .com * * @see SimpleDateFormat ??? * @param source ? * @param pattern * @return ????????<code>null</code>????????? */ public static Date paseDate(String source, String pattern) { if (StringUtils.isEmpty(source) || StringUtils.isEmpty(pattern)) { return null; } try { SimpleDateFormat format = new SimpleDateFormat(pattern); return format.parse(source); } catch (Exception e) { return null; } }
From source file:com.hackathon.gavin.currency.event.CurrencyEventCreater.java
/** * This method is used to convert RFC3339 format to normal date * * @param dateString in RFC3339 format//from ww w . j a v a2s . co m * @return date in java.util.Date format * @throws java.text.ParseException * @throws IndexOutOfBoundsException */ public static Date parseRFC3339Date(String dateString) throws java.text.ParseException, IndexOutOfBoundsException { Date currentDate = new Date(); if (dateString.endsWith("Z")) { try { SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"); currentDate = s.parse(dateString); } catch (java.text.ParseException pe) { pe.printStackTrace(); } return currentDate; } return currentDate; }
From source file:Main.java
public static java.util.Date ConvertFromWebService(String strDate) { java.lang.String[] formats = new java.lang.String[] { "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" }; for (java.lang.String frm : formats) { try {//from ww w. ja v a2s. c o m SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US); format.setTimeZone(java.util.TimeZone.getTimeZone("UTC")); return format.parse(strDate); } catch (java.lang.Exception ex) { } } return null; }
From source file:Main.java
public static boolean expireDate(String date) { Date todayDate = null;/*www . j av a 2s . c om*/ Date inputDate = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String today = sdf.format(new Date()); try { todayDate = sdf.parse(today); inputDate = sdf.parse(date); if (todayDate.compareTo(inputDate) <= 0) { return false; } else { return true; } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
From source file:Main.java
public static Calendar StringToCal(String date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm", Locale.KOREA); Date scheduleTime = null;/*w w w . j av a2 s . c o m*/ try { scheduleTime = sdf.parse(date); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(scheduleTime); return cal; }
From source file:Main.java
public static boolean judgeCurrTime(String time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date date = new Date(); try {/*from w w w. j ava2 s .co m*/ date = sdf.parse(time); long t = date.getTime(); long round = System.currentTimeMillis(); if (t - round > 0) { return true; } else { return false; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:it.inserpio.mapillary.gopro.importer.parser.bikematepro.transformer.BikeMateProGPXTransformer.java
public static List<GPXDateTimePoint> translate(BikeMateProGPX bikeMateProGPX) throws ParseException { List<GPXDateTimePoint> result = null; Assert.notNull(bikeMateProGPX);/*from w w w .jav a2 s . c o m*/ Assert.notNull(bikeMateProGPX.getTrk()); if (CollectionUtils.isNotEmpty(bikeMateProGPX.getTrk().getTrksegs())) { for (BikeMateProTRKSEG bikeMateProTRKSEG : bikeMateProGPX.getTrk().getTrksegs()) { result = new ArrayList<GPXDateTimePoint>(); for (BikeMateProTRKPT bikeMateProTRKPT : bikeMateProTRKSEG.getTrkpts()) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); Date date = dateFormat.parse(bikeMateProTRKPT.getTime()); result.add(new GPXDateTimePoint(bikeMateProTRKPT.getLon(), bikeMateProTRKPT.getLat(), date.getTime())); } } } return result; }
From source file:com.pinterest.deployservice.common.CommonUtils.java
public static Long convertDateStringToMilliseconds(String dateString) throws Exception { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:SS"); Date date = formatter.parse(dateString); return date.getTime(); }
From source file:Main.java
public static Date parse(String dateString) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(rfc822DateFormat); Date parsedDate = null;/*from w w w.ja v a 2s .c o m*/ try { parsedDate = simpleDateFormat.parse(dateString); } catch (ParseException e) { throw new IllegalArgumentException("Unable to parseMultipart '" + dateString + "' into a date using format '" + rfc822DateFormat + "'"); } return parsedDate; }
From source file:Main.java
/** * Parse a {@link String} that contains a valid date with time zone. * * @param dateTime//ww w .ja v a2 s.c o m * @return */ public static Date parseTimeZone(@NonNull String dateTime) { final SimpleDateFormat timeZoneParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Date parsed = null; try { parsed = timeZoneParser.parse(dateTime); } catch (Exception e) { e.printStackTrace(); } return parsed; }