Java Date Parse getDateFromString(String dateString)

Here you can find the source of getDateFromString(String dateString)

Description

Returns a Date objected parsed from a given string representing a date.

License

Open Source License

Parameter

Parameter Description
dateString The string representing a date in the format "dd.MM.yyyy HH:mm".

Exception

Parameter Description
ParseException an exception

Return

A date object

Declaration

public static Date getDateFromString(String dateString) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from  w w  w  .ja  va  2s.c om*/
     * Returns a Date objected parsed from a given string representing a date.
     * 
     * <pre>
     * {@code
     * Date date = getDateFromString("10.09.1993 18:58")
     * System.out.println(date.toString());
     * >> Fri Sep 10 18:58:00 CLT 1993
     * }
     * </pre>
     * 
     * @param dateString
     *            The string representing a date in the format
     *            "dd.MM.yyyy HH:mm".
     * @return A date object
     * @throws ParseException
     */
    public static Date getDateFromString(String dateString) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
        try {
            Date date = dateFormat.parse(dateString);
            return date;
        } catch (ParseException e) {
            System.out.println(dateString + " is unparseable using " + dateFormat);
        }
        return new Date();
    }
}

Related

  1. getDateFromString(String date, String pattern)
  2. getDatefromString(String dateStr)
  3. getDateFromString(String dateStr, String datePattern)
  4. getDateFromString(String dateString)
  5. getDateFromString(String dateString)
  6. getDateFromString(String dateString, String format)
  7. getDateFromString(String dateString, String format)
  8. getDateFromString(String input, String format)
  9. getDateFromString(String iso, String format)