Here you can find the source of convertStringToDate(String str_date)
Parameter | Description |
---|---|
str_date | the str_date |
public static Date convertStringToDate(String str_date)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//from www . j a v a 2 s.co m * Convert string to date. * * @param str_date * the str_date * @return the date */ public static Date convertStringToDate(String str_date) { if (str_date != null && str_date.length() == 19) return convertStringToDateWithTime(str_date); Date dt = null; SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); try { if (str_date != null) { dt = (Date) formatter.parse(str_date); } } catch (ParseException e) { e.printStackTrace(); } return dt; } /** * Convert string to date with time. * * @param str_date * the str_date * @return the date */ public static Date convertStringToDateWithTime(String str_date) { Date dt = null; SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm a"); try { if (str_date != null) { dt = (Date) formatter.parse(str_date); } } catch (ParseException e) { e.printStackTrace(); } return dt; } }