Java Date Parse dateFromString(String date, String pattern)

Here you can find the source of dateFromString(String date, String pattern)

Description

Convert date string with pattern to date

License

Open Source License

Parameter

Parameter Description
date a parameter
pattern a parameter

Exception

Parameter Description
Throwable an exception

Declaration

public static Date dateFromString(String date, String pattern) throws Throwable 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//from w  w w .  j a  v a  2s  .com
     * Convert date string with pattern to date
     * 
     * @param date
     * @param pattern
     * @return
     * @throws Throwable
     */
    public static Date dateFromString(String date, String pattern) throws Throwable {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);

        try {
            return formatter.parse(date);
        } catch (Throwable ex) {
            throw new RuntimeException("The date string " + date + " is not in an expected format");
        }
    }
}

Related

  1. dateFromISO8601(String iso)
  2. dateFromISO8601(String time)
  3. dateFromISODate(String isoDate)
  4. dateFromString(final String value)
  5. dateFromString(String date)
  6. dateFromString(String dateString)
  7. dateFromString(String dateString)
  8. dateFromString(String s)
  9. dateFromString(String value)