List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:com.shazam.dataengineering.pipelinebuilder.PipelineObject.java
public static Date getDate(String date) throws java.text.ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat(PIPELINE_DATE_FORMAT); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return dateFormat.parse(date); }
From source file:com.tieuluan.struts2.utils.AppSetting.java
/** * Gets the date value.//from w ww . j a va 2s. c o m * * @param name * the name * @return the date value */ public static Date getDateValue(String name) { String val = getStringValue(name); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date; try { date = format.parse(val); } catch (Exception ex) { date = null; } return date; }
From source file:com.common.server.AppLicenceUtil.java
public static void logonVertify() throws Exception { Map map = getLicence();/* w w w.j a va 2 s .co m*/ String expire = (String) map.get("expireDate"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); if (expire == null) { return; } Date expireDate = null; try { expireDate = format.parse(expire); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Date currentDate = new Date(); if (currentDate.compareTo(expireDate) >= 0) { log.info(":expire=" + expire + " currentDate=" + format.format(currentDate)); } log.info(":expire=" + expire + " currentDate=" + format.format(currentDate)); }
From source file:Main.java
public static String getConvertDate(String dateStr) { SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy"); String dateString = dateStr.replace("Z", "GMT+00:00"); dateFormat.setTimeZone(TimeZone.getDefault()); Date date = null;//from w ww . j av a 2s .com try { date = dateFormat.parse(dateString); } catch (java.text.ParseException e1) { e1.printStackTrace(); } dateFormat = new SimpleDateFormat("hh:mm a - dd MMM yy"); String outputText = dateFormat.format(date); return outputText; }
From source file:info.magnolia.cms.util.DateUtil.java
/** * Convert a string date from a dialog date to a UTC calendar ready to be stored in the repository *///from www . jav a 2 s. c o m public static Calendar getUTCCalendarFromDialogString(String dateString) throws ParseException { SimpleDateFormat sdf = (dateString.length() > YYYY_MM_DD.length()) ? new SimpleDateFormat(YYYY_MM_DD_T_HH_MM_SS) : new SimpleDateFormat(YYYY_MM_DD); return getUTCCalendarFromLocalDate(sdf.parse(dateString)); }
From source file:Main.java
public static Date getStartDateOfMonth(int year, int month) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, month); cal.set(Calendar.YEAR, year); String startdat = year + "-" + (month + 1) + "-01"; Date startdate = sdf.parse(startdat); return startdate; }
From source file:gemlite.core.common.DateUtil.java
public static Date stringToDate(String dateStr, String format, Locale locale) { SimpleDateFormat sdf = new SimpleDateFormat(format, locale); Date s_date = null;//w w w . j a v a 2 s. co m try { s_date = (Date) sdf.parse(dateStr); } catch (ParseException e) { LogUtil.getAppLog().error("DateUtil.stringToDate errr.DateStr:" + dateStr + " fmt:" + format); s_date = correctDate(dateStr, format); } return s_date; }
From source file:Main.java
public static Date parse(String dateFormatted, SimpleDateFormat dateFormat, boolean useUtc) { Date date = null;//from w ww .j a va 2 s . c om if (!dateFormatted.isEmpty()) { try { if (useUtc) { dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); } date = dateFormat.parse(dateFormatted); } catch (Exception e) { throw new RuntimeException( "Error parsing the dateFormatted: " + dateFormatted + " pattern: " + dateFormat.toPattern(), e); } } return date; }
From source file:gemlite.core.common.DateUtil.java
private static Date correctDate(String dateStr, String format) { Map<String, Locale> set = new HashMap<String, Locale>(); set.put(US_MMM_dd_yyyy_hhmmssSSSaa, Locale.US); set.put(yyyyMMdd_HHmmssSSS, Locale.US); set.put(US_EEE_MMM_dd_hhmmsszyyyy, Locale.US); set.put(yyyyMMdd_HHmmssSSS, Locale.getDefault()); set.put(yyyy_MM_dd_HHmmss_SSS, Locale.getDefault()); set.remove(format);/*w w w .j av a 2 s. c o m*/ for (Entry<String, Locale> es : set.entrySet()) { SimpleDateFormat sdf = new SimpleDateFormat(es.getKey(), es.getValue()); try { Date s_date = sdf.parse(dateStr); LogUtil.getAppLog().error("DateUtil.correctDate work.DateStr:" + dateStr + " fmt:" + es.getKey()); return s_date; } catch (ParseException e) { LogUtil.getAppLog().error("DateUtil.correctDate errr.DateStr:" + dateStr + " fmt:" + es.getKey()); } } return null; }
From source file:com.worldline.easycukes.rest.utils.DateHelper.java
/** * Checks if the given string matching a date expression * * @param expression//from w w w . j a v a2 s . c o m * @return true if the specified string matching a date expression */ public static boolean isDateExpression(@NonNull String expression) { if (expression.startsWith(RestConstants.TODAY) || expression.startsWith(RestConstants.YESTERDAY) || expression.startsWith(RestConstants.TOMORROW)) return true; final SimpleDateFormat simpleDateFormat = new SimpleDateFormat( ExecutionContext.get(RestConstants.DATE_FORMAT)); try { simpleDateFormat.parse(expression); return true; } catch (final ParseException e) { return false; } }