List of usage examples for java.text SimpleDateFormat parse
public Date parse(String source) throws ParseException
From source file:Main.java
public static long parse_iso_time_string_to_long(String iso_time_string) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ssZ"); return sdf.parse(iso_time_string).getTime(); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static long time2Mills(String time) { SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {//from www .j a v a 2 s. c om return sdf2.parse(time).getTime(); } catch (ParseException e) { e.printStackTrace(); } return System.currentTimeMillis(); }
From source file:Main.java
/** * Take an ISO 8601 string and return a Date object. * On failure, returns null./*from w w w .j a va2 s. c om*/ */ public static Date getDateFromIso8601String(String s) { SimpleDateFormat df = new SimpleDateFormat(ISO_8601_FORMAT); try { return df.parse(s); } catch (ParseException e) { Log.e("DateUtilities", "Error parsing ISO 8601 date"); return null; } }
From source file:Main.java
public static String getTimestampDate(String dateString, String formatString) { SimpleDateFormat format = new SimpleDateFormat(formatString); try {//from www .ja va2 s . co m return String.valueOf(format.parse(dateString).getTime()); } catch (Exception e) { return ""; } }
From source file:Main.java
public static java.util.Date getDateByForm(String str, String dateform) { if (str == null || dateform == null) return null; SimpleDateFormat sdf = new SimpleDateFormat(dateform); try {/*ww w . j av a2 s .co m*/ java.util.Date date = sdf.parse(str); return date; } catch (Exception e) { return null; } }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static long parse_iso_time_string_to_long(String iso_time_string) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd'T'HH:mm:ssZ"); return sdf.parse(iso_time_string).getTime(); }
From source file:Main.java
public static Calendar timeStringToCalendar(String timeString) { try {/*from w ww . j av a 2 s. c om*/ SimpleDateFormat formatter = new SimpleDateFormat("HH:mm", Locale.CHINESE); Date date = formatter.parse(timeString); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar; } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Date string2Date(String yyyyMMdd) { if (null != yyyyMMdd && yyyyMMdd.matches("^\\d{8}$")) { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); try {// w w w.j av a 2 s .c o m return format.parse(yyyyMMdd); } catch (ParseException e) { return new Date(); } } return new Date(); }
From source file:Main.java
/** * parse date using default pattern yyyy-MM-dd * * @param strDate//w ww . ja va2 s. c om * @return */ public static final Date parseDate(String strDate) { Date date = null; try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); date = dateFormat.parse(strDate); return date; } catch (Exception pe) { return null; } }
From source file:Main.java
public static Date dateXMLStringToDateControlador(SimpleDateFormat formatter, String sDate) { Date date = null;/*from ww w.j av a 2s . com*/ try { date = formatter.parse(sDate); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date; }