Java Parse Date parseDateFromString(String valor, String formatoFecha)

Here you can find the source of parseDateFromString(String valor, String formatoFecha)

Description

parse Date From String

License

Open Source License

Declaration

public static Object parseDateFromString(String valor, String formatoFecha) throws Exception 

Method Source Code

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

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

public class Main {
    public static Object parseDateFromString(String valor, String formatoFecha) throws Exception {

        try {//from  www. j a v  a  2 s .  co  m
            SimpleDateFormat dateFormat = new SimpleDateFormat(formatoFecha);

            if (valor.trim().length() != dateFormat.toPattern().length())
                throw new IllegalArgumentException("No tiene un formato de fecha correcto : " + formatoFecha);

            dateFormat.setLenient(Boolean.FALSE);

            return dateFormat.parse(valor.trim());
        } catch (ParseException pe) {
            throw new IllegalArgumentException("No tiene un formato de fecha correcto o la fecha no existe: ("
                    + formatoFecha + " ) - " + valor);
        }

    }
}

Related

  1. parseDateFrom(String dateStr)
  2. parseDateFromDateStr(String date)
  3. parseDateFromDateTimeStr(String date)
  4. parseDateFromDefault(String dateString)
  5. parseDateFromHeader(String datestr)
  6. parseDateHeader(String header)
  7. parseDateHeader(String value)
  8. parseDateHHmm(java.util.Date date)
  9. parseDateHHMM(String hhmm)