Here you can find the source of parseDate(String dateString)
Parameter | Description |
---|---|
dateString | a parameter |
public static Date parseDate(String dateString)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**/* w ww .jav a 2s . c o m*/ * Method parseDate. Return java.util.Date for a given MM/DD/YYYY format string date. * * @param dateString * @return Date */ public static Date parseDate(String dateString) { // Null conditions if (dateString == null) return null; if (dateString.length() == 0) return null; // Initialize to null Date javaDate = null; // If there is a date dateString = dateString.trim(); if (dateString.length() <= 10) // Just date { try { javaDate = new SimpleDateFormat("MM/dd/yyyy").parse(dateString); } catch (ParseException pe) { } } else if (dateString.length() > 10) // Date + time { // Try a couple of different formats for date/time try { javaDate = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa").parse(dateString); } catch (ParseException pe) { } if (javaDate == null) { try { javaDate = new SimpleDateFormat("MM/dd/yyyy hh:mm aaa").parse(dateString); } catch (ParseException pe) { } } } return javaDate; } }