Android Date String Parse stringToDate(String str)

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

Description

string To Date

Declaration

public synchronized static Date stringToDate(String str) 

Method Source Code

//package com.java2s;

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

public class Main {
    static SimpleDateFormat format = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");

    public synchronized static Date stringToDate(String str) {
        if (isBlank(str)) {
            return null;
        }/*from   ww w . j  av a 2s. co m*/
        try {
            return format.parse(str);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * 
     * @param str
     * @return
     */
    public static boolean isBlank(String str) {
        if (str == null || str.trim().length() == 0) {
            return true;
        }
        return false;
    }
}

Related

  1. parseDateString(String dateStr, String pattern)
  2. parseDateString(String dateStr, String pattern, Locale locale)
  3. parseSimpleDate(String dateString)
  4. parseUTCFormattedDateString(String dateString)
  5. parseYoutubeDate(String rawDate)
  6. toDate(String sdate)
  7. toDate(String sdate)
  8. toDateFormat(String d, String delim)
  9. parseDate(CharSequence input)