Android Date String Parse parse(String dateStr)

Here you can find the source of parse(String dateStr)

Description

Converts the given string into a java.util.Date object using the defined default format yyyy-MM-dd HH:mm

Parameter

Parameter Description
dateStr a string representing a date

Return

the Date object created from the date string, or null if format incorrect.

Declaration

public static Date parse(String dateStr) 

Method Source Code

import android.util.Log;
import com.archee.picturedownloader.PictureDownloader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{
    public static final SimpleDateFormat DEFAULT_FORMATTER = new SimpleDateFormat(
            DEFAULT_FORMAT);/*from w  w w  .  j a v a  2  s.co m*/
    /**
     * Converts the given string into a java.util.Date object using the defined default format yyyy-MM-dd HH:mm
     * @param dateStr a string representing a date
     * @return the Date object created from the date string, or null if format incorrect.
     */
    public static Date parse(String dateStr) {
        Date parsedDate;

        try {
            parsedDate = DEFAULT_FORMATTER.parse(dateStr);
        } catch (ParseException e) {
            Log.e(PictureDownloader.TAG, "Error parsing date string: "
                    + dateStr + " - returning current date...");
            parsedDate = new Date();
        }

        return parsedDate;
    }
}

Related

  1. parseString(String dateStr)
  2. parseString(String dateStr, String pattern)
  3. parseStringToDate(String str)
  4. parseTM(String s, boolean end)
  5. parseDate(String date)
  6. parse(String input)
  7. parse(String source, String pattern)
  8. parseDate(String value, String[] parsePatterns)
  9. parseJsonDate(String jsonDate)