Here you can find the source of dateFromString(String date, String pattern)
Parameter | Description |
---|---|
date | a parameter |
pattern | a parameter |
Parameter | Description |
---|---|
Throwable | an exception |
public static Date dateFromString(String date, String pattern) throws Throwable
//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"); } } }