List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:com.qagen.osfe.core.utils.BeanPopulator.java
private static Time getTime(String name, String value, String format) { try {//from w w w . jav a 2s. c o m if ((format == null) || (format.trim().length() == 0)) { final String message = "Column, " + name + " is define as a Time and must the attribute, format, defined."; throw new FeedErrorException(message); } final SimpleDateFormat formatter = new SimpleDateFormat(format); return new Time(formatter.parse(value).getTime()); } catch (ParseException e) { throw new FeedErrorException(e); } }
From source file:com.qagen.osfe.core.utils.BeanPopulator.java
private static Date getDate(String name, String value, String format) { try {//from w ww . j av a 2 s. c om if ((format == null) || (format.trim().length() == 0)) { final String message = "Column, " + name + " is define as a Date and must the attribute, format, defined."; throw new FeedErrorException(message); } final SimpleDateFormat formatter = new SimpleDateFormat(format); return new Date(formatter.parse(value).getTime()); } catch (ParseException e) { throw new FeedErrorException(e); } }
From source file:com.skipjaq.awspricing.pricing.AwsPricing.java
private static Date getDate(String dateTime) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); try {//from w w w . jav a 2s. c o m Date date = formatter.parse(dateTime); return date; } catch (ParseException e) { Date currentDate = new Date(); Calendar c = Calendar.getInstance(); c.setTime(currentDate); c.roll(Calendar.DAY_OF_MONTH, 1); Date yesterday = c.getTime(); System.out.println("Parse date time went wrong, getting yesterday " + yesterday); return yesterday; } }
From source file:com.alibaba.ims.platform.util.DateUtil.java
/** * ?/*from ww w . ja v a 2 s. c om*/ * * @param dateStr * @param pattern * @return */ public static Date parse(String dateStr, String pattern) { if (StringUtils.isBlank(dateStr)) { return null; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); try { return simpleDateFormat.parse(dateStr); } catch (ParseException e) { logger.error("Parse string to date error.", e); return null; } }
From source file:com.prashsoft.javakiva.KivaUtil.java
public static Date getDateFromISO8601(String iso8601Date) { SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_DATE_FORMAT); try {// w w w .j a va2s . com return sdf.parse(iso8601Date); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:com.qagen.osfe.core.utils.BeanPopulator.java
private static Timestamp getTimestamp(String name, String value, String format) { try {/* www.j a v a 2 s. c o m*/ if ((format == null) || (format.trim().length() == 0)) { final String message = "Column, " + name + " is define as a Timestamp and must the attribute, format, defined."; throw new FeedErrorException(message); } final SimpleDateFormat formatter = new SimpleDateFormat(format); return new Timestamp(formatter.parse(value).getTime()); } catch (ParseException e) { throw new FeedErrorException(e); } }
From source file:jp.co.nemuzuka.utils.DateTimeChecker.java
/** * ?./* w w w. j ava 2 s . c o m*/ * @param target * @param patterns ? * @return true:?? false:????? */ private static boolean executeCheck(String target, String pattern) { if (StringUtils.isEmpty(target)) { return false; } if (target.length() != pattern.length()) { return false; } try { Integer.valueOf(target); } catch (NumberFormatException e) { return false; } SimpleDateFormat format = DateTimeUtils.createSdf(pattern); format.setLenient(false); try { format.parse(target); } catch (ParseException e) { return false; } return true; }
From source file:Main.java
/** * Get the Date from String with custom format. Default format is yyyy-MM-dd * //from w ww . jav a2 s. c om * @param dateString * @param dateFormat * @return * @throws ParseException */ public static Date getDateFromString(String dateString, String dateFormat) throws ParseException { SimpleDateFormat formatter; if (dateFormat == null) { formatter = yyyyMMddFormat; } else { formatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH); } return formatter.parse(dateString); }
From source file:Main.java
public static String changeDateFormat(String createDate) { String date = ""; SimpleDateFormat input = new SimpleDateFormat(DATE_SERVER_FORMAT); SimpleDateFormat output = new SimpleDateFormat(DATE_LOCAL_FORMAT); Date formatDate;/*w w w . ja v a2 s. co m*/ try { formatDate = input.parse(createDate); date = output.format(formatDate); } catch (ParseException pe) { pe.printStackTrace(); } return date; }
From source file:Main.java
@SuppressLint("SimpleDateFormat") static String futureDate() { // take current date and increment Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date currentLocalTime = cal.getTime(); SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd"); date.setTimeZone(TimeZone.getDefault()); _currentDate = date.format(currentLocalTime); try {//from ww w. j ava 2 s.c om cal.setTime(date.parse(_currentDate)); } catch (ParseException e) { e.printStackTrace(); } cal.add(Calendar.DATE, 30); _currentDate = date.format(cal.getTime()); return _currentDate; }