List of usage examples for java.text SimpleDateFormat applyPattern
public void applyPattern(String pattern)
From source file:Main.java
public static String getConverDateString(String date, String fromFormat, String toFormat) { if (TextUtils.isEmpty(date)) return ""; SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(fromFormat); Date d = null;//from ww w. jav a 2s .c om try { d = sdf.parse(date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } sdf.applyPattern(toFormat); return sdf.format(d); }
From source file:Main.java
public static Date parseDatetime(String datetime, String pattern) throws ParseException { SimpleDateFormat format = (SimpleDateFormat) datetimeFormat.clone(); format.applyPattern(pattern); return format.parse(datetime); }
From source file:Main.java
/** * * @param input Date for format//from w w w .j av a 2 s. c o m * @param pattern date pattern e.g. "yyyy.MM.dd" * @return */ public static String formateDate(Date input, String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern, new Locale("hu")); sdf.applyPattern(pattern); return sdf.format(input); }
From source file:Main.java
public static String dateToString(Date date, String pattern) { SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(); sdf.applyPattern(pattern); return sdf.format(date); }
From source file:Main.java
public static String formatDatetime(Date date, String pattern) { SimpleDateFormat customFormat = (SimpleDateFormat) datetimeFormat.clone(); customFormat.applyPattern(pattern); return customFormat.format(date); }
From source file:Main.java
/** * Formats a Date to the format YYYY-MM-DD. * * @param date the Date to parse./*from w w w .j a v a2 s . c om*/ * @return A formatted date string. Null if argument is null. */ public static String getMediumDateString(Date date) { final SimpleDateFormat format = new SimpleDateFormat(); format.applyPattern(DEFAULT_DATE_FORMAT); return date != null ? format.format(date) : null; }
From source file:Main.java
/** * Returns date before given days/*from w w w . j a va2 s . c o m*/ * * @param days days to before * @return string date string before days */ public static String getDateBefore(int days) { Date today = new Date(); Calendar cal = new GregorianCalendar(); cal.setTime(today); cal.add(Calendar.DAY_OF_MONTH, days * -1); Date date = cal.getTime(); SimpleDateFormat gmtFormat = new SimpleDateFormat(); gmtFormat.applyPattern("yyyy-MM-dd 00:00:00"); TimeZone gmtTime = TimeZone.getTimeZone("GMT"); gmtFormat.setTimeZone(gmtTime); return gmtFormat.format(date); }
From source file:Main.java
public static Date string2Date(String s, String style) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); simpleDateFormat.applyPattern(style); Date date = null;// w w w. ja va2s . c o m if (s == null || s.length() < 6) { return null; } try { date = simpleDateFormat.parse(s); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
/** * Parses a date from a String on the format YYYY-MM-DD. * * @param dateString the String to parse. * @return a Date based on the given String. *///from w w w .j a v a2s . co m public static Date getMediumDate(String dateString) { try { final SimpleDateFormat format = new SimpleDateFormat(); format.applyPattern(DEFAULT_DATE_FORMAT); return dateString != null && dateIsValid(dateString) ? format.parse(dateString) : null; } catch (ParseException ex) { throw new RuntimeException("Failed to parse medium date", ex); } }
From source file:Main.java
public static String dateString2dateString(String date, String originFormater, String destFormater) { if (date == null || "".equals(date)) return ""; SimpleDateFormat formater = new SimpleDateFormat(); try {//ww w . j a v a 2 s.com formater.applyPattern(originFormater); Date time = formater.parse(date); return date2String(destFormater, time); } catch (ParseException e) { e.printStackTrace(); } return ""; }