Java String to Date stringToDate(String strDate)

Here you can find the source of stringToDate(String strDate)

Description

string To Date

License

LGPL

Declaration

public static Date stringToDate(String strDate) throws ParseException 

Method Source Code


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

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";

    public static Date stringToDate(String strDate) throws ParseException {
        DateFormat df = new SimpleDateFormat(DATE_FORMAT);
        Date result = null;//from   w w  w . ja  v a2  s .c o m
        if (!isBlank(strDate)) {
            result = df.parse(strDate);
        }
        return result;
    }

    public static boolean isBlank(CharSequence cs) {
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((Character.isWhitespace(cs.charAt(i)) == false)) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. stringToDate(String str, String format)
  2. stringToDate(String str, String formatStr)
  3. stringToDate(String strDate)
  4. stringToDate(String strDate)
  5. stringToDate(String strDate)
  6. stringToDate(String strDate, String formartStr)
  7. stringToDate(String strDate, String oracleFormat)
  8. stringToDate(String strDate, String pattern)
  9. stringToDate(String strDate, String strFormat)