Java Date Parse convertStringToDate(String aMask, String strDate)

Here you can find the source of convertStringToDate(String aMask, String strDate)

Description

This method generates a string representation of a date/time in the format you specify on input

License

LGPL

Parameter

Parameter Description
aMask the date pattern the string is in
strDate a string representation of a date

Exception

Parameter Description
ParseException an exception

Return

a converted Date object

Declaration

public static final Date convertStringToDate(String aMask, String strDate) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

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

import java.util.Date;

public class Main {
    /**/*from   w  ww.  ja  v  a  2 s.c o  m*/
     * This method generates a string representation of a date/time in the format you specify on input
     * @param aMask
     *        the date pattern the string is in
     * @param strDate
     *        a string representation of a date
     * @return a converted Date object
     * @see java.text.SimpleDateFormat
     * @throws ParseException
     */
    public static final Date convertStringToDate(String aMask, String strDate) {
        SimpleDateFormat df = null;
        Date date = null;
        df = new SimpleDateFormat(aMask);
        try {
            date = df.parse(strDate);
        } catch (ParseException pe) {
            throw new IllegalArgumentException(pe.getMessage() + " " + pe.getErrorOffset());
        }

        return (date);
    }
}

Related

  1. convertDateStringToDB(String date)
  2. convertDateStringToMilliseconds(String dateString)
  3. convertIntToDate(int date)
  4. convertIntToDatePattern2(int date)
  5. convertLongToDate(final long time)
  6. convertStringToDate(String aMask, String strDate)
  7. convertStringToDate(String arg)
  8. convertStringToDate(String data)
  9. convertStringToDate(String date)