Android Utililty Methods Date String Parse

List of utility methods to do Date String Parse

Description

The list of methods to do Date String Parse are organized into topic(s).

Method

Dateparse(String dateStr)
Converts the given string into a java.util.Date object using the defined default format yyyy-MM-dd HH:mm
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;
Dateparse(String input)
parse
return new SimpleDateFormat("yyyyMMddHHmmss").parse(input);
Dateparse(String source, String pattern)
parse
if (source == null) {
    return null;
Date date;
try {
    date = getFormat(pattern).parse(source);
} catch (ParseException e) {
    return null;
...
DateparseDate(String value, String[] parsePatterns)
parse Date
if (value == null || parsePatterns == null) {
    throw new IllegalArgumentException(
            "Date and Patterns must not be null");
SimpleDateFormat parser = null;
ParsePosition pos = new ParsePosition(0);
for (int i = 0; i < parsePatterns.length; i++) {
    if (i == 0) {
...
DateparseJsonDate(String jsonDate)
parse Json Date
Date d = null;
if (jsonDate != null) {
    d = parseDate(jsonDate, FORMAT_4);
    if (d == null) {
        d = parseDate(jsonDate);
return d;
...
java.sql.Datestr2Date(String str)
str Date
if (str == null)
    return null;
str = str.trim();
if (!str.matches("^\\d\\d\\d\\d-\\d\\d-\\d\\d$")
        && !str.matches("^\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d$"))
    return null;
String[] ss = str.split("-| |:");
GregorianCalendar gc = new GregorianCalendar();
...
DatestringConvertDate(String date)
string Convert Date
if (null == date || "".equals(date)) {
    return null;
if (date.length() == 10) {
    date = date + " 00:00:00";
} else if (date.length() == 16) {
    date = date + ":00";
SimpleDateFormat formatter = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");
Date objDate;
try {
    objDate = formatter.parse(date);
} catch (ParseException e) {
    objDate = null;
return objDate;
DatestringToDate(String date)
string To Date
formatter.setTimeZone(TimeZone.getTimeZone("gmt"));
return (formatter.parse(date));
DatetoDate(String string)
to Date
return new Date();
int[]tokenizeDate(String date)
tokenize Date
StringTokenizer st = new StringTokenizer(date, "-/");
ArrayList<Integer> al = new ArrayList<Integer>();
while (st.hasMoreTokens()) {
    al.add(Integer.parseInt(st.nextToken()));
int[] tokenList = new int[3];
for (int i = 0; i < al.size(); i++) {
    tokenList[i] = al.get(i);
...