Java String to Date stringToDate(String pstrValue, String pstrDateFormat)

Here you can find the source of stringToDate(String pstrValue, String pstrDateFormat)

Description

Convert string to Date

License

Apache License

Return

a java.util.Date object converted.

Declaration

public static java.util.Date stringToDate(String pstrValue, String pstrDateFormat) 

Method Source Code

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

import java.text.SimpleDateFormat;

public class Main {
    /**/*  w  w w.ja  v  a2  s .  c om*/
     * Convert string to Date
     * 
     * @return a java.util.Date object converted.
     */
    public static java.util.Date stringToDate(String pstrValue, String pstrDateFormat) {
        if ((pstrValue == null) || (pstrValue.equals(""))) {
            return null;
        }
        java.util.Date dttDate = null;
        try {
            SimpleDateFormat oFormatter = new SimpleDateFormat(pstrDateFormat);
            dttDate = oFormatter.parse(pstrValue);
            oFormatter = null;
        } catch (Exception e) {
            return null;
        }

        return dttDate;
    }
}

Related

  1. StringToDate(String Expression)
  2. StringToDate(String fecha)
  3. stringToDate(String fecha, String formato)
  4. StringToDate(String format, String dateStr)
  5. stringToDate(String input)
  6. stringToDate(String s)
  7. StringToDate(String s)
  8. stringToDate(String s)
  9. StringToDate(String s)