Here you can find the source of toDate(String pString, String pFormat)
Parameter | Description |
---|---|
pString | the string to convert |
pFormat | the date format |
public static Date toDate(String pString, String pFormat)
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**/* www . j a v a 2 s. co m*/ * Converts the string to a date, using the default date format. * * @param pString the string to convert * @return the date * @see DateFormat * @see DateFormat#getInstance() */ public static Date toDate(String pString) { // Default return toDate(pString, DateFormat.getInstance()); } /** * Converts the string to a date, using the given format. * * @param pString the string to convert * @param pFormat the date format * @return the date * @todo cache formats? * @see java.text.SimpleDateFormat * @see java.text.SimpleDateFormat#SimpleDateFormat(String) */ public static Date toDate(String pString, String pFormat) { // Get the format from cache, or create new and insert // Return new date return toDate(pString, new SimpleDateFormat(pFormat)); } /** * Converts the string to a date, using the given format. * * @param pString the string to convert * @param pFormat the date format * @return the date * @see SimpleDateFormat * @see SimpleDateFormat#SimpleDateFormat(String) * @see DateFormat */ public static Date toDate(final String pString, final DateFormat pFormat) { try { synchronized (pFormat) { // Parse date using given format return pFormat.parse(pString); } } catch (ParseException pe) { // Wrap in RuntimeException throw new IllegalArgumentException(pe.getMessage()); } } }