List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:com.sinpo.xnfc.nfc.Util.java
public static String getTime() { Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("", Locale.SIMPLIFIED_CHINESE); dateFormat.applyPattern("yyyy"); dateFormat.applyPattern("MM"); dateFormat.applyPattern("dd"); dateFormat.applyPattern("[yyyy-MM-dd HH:mm:ss]"); String time = dateFormat.format(date); return time;// ww w. j a v a2 s. co m }
From source file:org.apache.hama.bsp.TaskLog.java
public static File getLocalTaskLogFile(LogName filter, String stringPattern) { // TODO clean up the log path and type. SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(stringPattern); return new File(LOG_DIR, "job_" + sdf.format(new Date()) + "/" + "local_" + sdf.format(new Date()) + ((filter == LogName.STDERR) ? ".err" : ".log")); }
From source file:org.vpac.ndg.Utils.java
/** * Tries a list of allowable date formats when parsing the specified date. * /*from w w w. ja v a 2 s. c o m*/ * @param str * A string representation of the date. * @return The parsed date. * @throws IllegalArgumentException * if the date can't be parsed. */ public static Date parseDate(String str) throws IllegalArgumentException { Date result = null; SimpleDateFormat formatter = new SimpleDateFormat(); formatter.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC"))); for (String pattern : StringUtils.ALLOWABLE_DATETIME_PATTERNS) { try { formatter.applyPattern(pattern); result = formatter.parse(str); if (result != null) { break; } } catch (ParseException e) { } catch (IllegalArgumentException e) { } } if (result == null) { throw new IllegalArgumentException(String.format("Could not parse date \"%s\".", str)); } return result; }
From source file:surrey.csv.profile.expression.DateExpressionEvaluator.java
public static Date getDate(String input) { SimpleDateFormat df = new SimpleDateFormat(); String pattern = df.toPattern(); String value = input;//from w ww . j a v a 2s . c o m if (input.indexOf(PATTERN_SEPARATOR) > -1) { pattern = input.substring(0, input.indexOf(PATTERN_SEPARATOR)); value = input.substring(input.indexOf(PATTERN_SEPARATOR) + PATTERN_SEPARATOR.length()); } df.applyPattern(pattern); try { Date date = df.parse(value); return date; } catch (ParseException e) { return null; } }
From source file:com.zxy.commons.lang.utils.DatesUtils.java
/** * ??,?DateType??/*from w ww . ja v a 2 s . com*/ * * @param dateString dateString * @return Date */ @SuppressWarnings("PMD.EmptyCatchBlock") public static Date getDate(String dateString) { if (StringUtils.isEmpty(dateString)) { return null; } Date date = null; SimpleDateFormat df = new SimpleDateFormat(); for (DatesUtils dateType : DatesUtils.values()) { try { String pattern = dateType.getDateType(); df.applyPattern(pattern); date = df.parse(dateString); return date; } catch (ParseException ex) { // ex.printStackTrace(); } } return date; }
From source file:com.netscape.cmsutil.util.Utils.java
public static String lsDateStr(Date date) { long dateTime = date.getTime(); if (dateTime == -1L) return "------------"; long nowTime = System.currentTimeMillis(); SimpleDateFormat formatter = new SimpleDateFormat(); if (Math.abs(nowTime - dateTime) < 183L * 24L * 60L * 60L * 1000L) formatter.applyPattern("MMM dd hh:ss"); else/*from w w w.j a v a 2 s .com*/ formatter.applyPattern("MMM dd yyyy"); return formatter.format(date); }
From source file:com.luke.lukef.lukeapp.tools.LukeUtils.java
/** * Parses date from MS to the defined format * * @param submission_date The amount of milliseconds from the Jan 1, 1970 GMT to the desired date * @return Date as String in defined format *//*from ww w. ja v a2 s . co m*/ public static String parseDateFromMillis(long submission_date) { Date date = new Date(submission_date); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.CHINA); format.applyPattern("hh:mm dd/MM/yyyy"); return format.format(date); }
From source file:DateUtil.java
/** * Parses the date value using the given date formats. * * @param dateValue the date value to parse * @param dateFormats the date formats to use * @param startDate During parsing, two digit years will be placed in the range * <code>startDate</code> to <code>startDate + 100 years</code>. This value may * be <code>null</code>. When <code>null</code> is given as a parameter, year * <code>2000</code> will be used. * @return the parsed date/*from ww w. j ava 2s . co m*/ * @throws DateParseException if none of the dataFormats could parse the dateValue */ public static Date parseDate(String dateValue, Collection<String> dateFormats, Date startDate) { if (dateValue == null) { throw new IllegalArgumentException("dateValue is null"); } if (dateFormats == null) { dateFormats = DEFAULT_PATTERNS; } if (startDate == null) { startDate = DEFAULT_TWO_DIGIT_YEAR_START; } // trim single quotes around date if present // see issue #5279 if (dateValue.length() > 1 && dateValue.startsWith("'") && dateValue.endsWith("'")) { dateValue = dateValue.substring(1, dateValue.length() - 1); } SimpleDateFormat dateParser = null; for (String format : dateFormats) { if (dateParser == null) { dateParser = new SimpleDateFormat(format, Locale.US); dateParser.setTimeZone(TimeZone.getTimeZone("GMT")); dateParser.set2DigitYearStart(startDate); } else { dateParser.applyPattern(format); } try { return dateParser.parse(dateValue); } catch (ParseException pe) { // ignore this exception, we will try the next format } } // we were unable to parse the date throw new RuntimeException("Unable to parse the date " + dateValue); }
From source file:org.sakaiproject.contentreview.turnitin.util.TurnitinAPIUtil.java
public static String getGMTime() { // calculate function2 data SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance()); dform.applyPattern("yyyyMMddHH"); dform.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); String gmtime = dform.format(cal.getTime()); gmtime += Integer.toString(((int) Math.floor((double) cal.get(Calendar.MINUTE) / 10))); return gmtime; }
From source file:util.android.util.DateUtils.java
public static String formatLongDate(Date inDate) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(ordinalMasks[1]); return sdf.format(inDate); }