Android Date String Parse parseStringToDate(String str)

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

Description

parse String To Date

Declaration

public static Date parseStringToDate(String str) throws ParseException

Method Source Code

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final String[] parsePatterns = new String[] {
            "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "HH:mm",
            "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd", "yyyyMMdd" };

    public static Date parseStringToDate(String str) throws ParseException {
        return parseDate(str, "yyyyMMddHHmm");
    }//  w  w w .  j a  va 2  s  . c  om

    public static Date parseDate(String str) throws ParseException {

        return parseDate(str, parsePatterns[1]);
    }

    public static Date parseDate(String str, String parsePattern)
            throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat(parsePattern);
        Date date = null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;

    }
}

Related

  1. parseDateWithLeniency(String str, String[] parsePatterns, boolean lenient)
  2. parseLongFormat(String dateString)
  3. parseSearchApiDateTime(String dateString)
  4. parseString(String dateStr)
  5. parseString(String dateStr, String pattern)
  6. parseTM(String s, boolean end)
  7. parseDate(String date)
  8. parse(String dateStr)
  9. parse(String input)