List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:org.eclipse.smila.utils.xml.XMLUtils.java
public static Date decodeDate(String xmlDate) throws ParseException { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd"); return df.parse(xmlDate); }
From source file:org.eclipse.smila.utils.xml.XMLUtils.java
public static Date decodeDateTime(String xmlDate) throws ParseException { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd'T'hh:mm:ss"); return df.parse(xmlDate); }
From source file:org.eclipse.smila.utils.xml.XMLUtils.java
public static String encodeDate(Date javaDate) { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd"); return df.format(javaDate); }
From source file:org.eclipse.smila.utils.xml.XMLUtils.java
public static String encodeDateTime(Date javaDate) { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd'T'hh:mm:ss"); return df.format(javaDate); }
From source file:org.pentaho.reporting.libraries.docbundle.BundleUtilities.java
public static Date parseDate(final String date) { if (date.startsWith("PT")) { return parseDuration(date); }/* ww w. j a v a 2s . c o m*/ final SimpleDateFormat dateFormat = new SimpleDateFormat(); dateFormat.setLenient(false); for (int i = 0; i < DATEFORMATS.length; i++) { try { final String dateformat = DATEFORMATS[i]; dateFormat.applyPattern(dateformat); return dateFormat.parse(date); } catch (ParseException e) { // ignore } } return null; }
From source file:Main.java
public static Date parseRFC3339Date(String date) { Date result = null;/*from w w w.java 2s . com*/ SimpleDateFormat format = RFC3339Formatter.get(); boolean isLocal = date.endsWith("Z"); if (date.contains(".")) { // remove secfrac int fracIndex = date.indexOf("."); String first = date.substring(0, fracIndex); String second = null; if (isLocal) { second = date.substring(date.length() - 1); } else { if (date.contains("+")) { second = date.substring(date.indexOf("+")); } else { second = date.substring(date.indexOf("-")); } } date = first + second; } if (isLocal) { try { result = format.parse(date); } catch (ParseException e) { e.printStackTrace(); } } else { format.applyPattern(RFC3339LOCAL); // remove last colon StringBuffer buf = new StringBuffer(date.length() - 1); int colonIdx = date.lastIndexOf(':'); for (int x = 0; x < date.length(); x++) { if (x != colonIdx) buf.append(date.charAt(x)); } String bufStr = buf.toString(); try { result = format.parse(bufStr); } catch (ParseException e) { e.printStackTrace(); Log.e(TAG, "Unable to parse date"); } finally { format.applyPattern(RFC3339UTC); } } return result; }
From source file:com.funambol.exchange.util.DateTools.java
/** * Converts a date in exchange task webdav format to funambol * /*from w w w . j a v a 2s.c om*/ * @param date * @return * @throws com.funambol.exchange.xml.XmlParseException */ public static String exchangeTaskDateToFunambolTaskDate(String date) throws XmlParseException { SimpleDateFormat formatter; Date dt; String value; if (date != null && date.length() > 0) { value = date; formatter = new SimpleDateFormat(DATE_FORMAT_WEBDAV); try { dt = formatter.parse(value); } catch (ParseException e) { throw new XmlParseException("Error converting date", e); } formatter.applyPattern(ANNIVERSARY_FORMAT_PDI); return formatter.format(dt); } else { return null; } }
From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.util.XMLUtils.java
/** * Decodes a Date./*from w ww . java 2s . c o m*/ * * @param xmlDate * the xmlDate * @return a Date * @throws ParseException * if any error occurs */ public static Date decodeDate(String xmlDate) throws ParseException { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd"); return df.parse(xmlDate); }
From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.util.XMLUtils.java
/** * Decodes a DateTime.//from ww w . jav a 2 s . c om * * @param xmlDate * the xmlDate * @return Date * @throws ParseException * if any error occurs */ public static Date decodeDateTime(String xmlDate) throws ParseException { final SimpleDateFormat df = new SimpleDateFormat(); df.applyPattern("yyyy-MM-dd'T'hh:mm:ss"); return df.parse(xmlDate); }
From source file:org.lnicholls.galleon.util.Tools.java
public static String hexToDate(String hex) { Date date = new Date(); try {// ww w . ja v a 2s . com Long time = Long.decode(hex); date = new Date(time.longValue() * 1000); } catch (NumberFormatException ex) { } SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("EEE MMM d yyyy, hh:mm:ss a"); return sdf.format(date); }