Android Date String Parse parse(String source, String pattern)

Here you can find the source of parse(String source, String pattern)

Description

parse

License

Open Source License

Parameter

Parameter Description
source a parameter
pattern a parameter

Return

Date

Declaration

public static Date parse(String source, String pattern) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

import java.util.HashMap;
import java.util.Map;

public class Main {
    private static final Map<String, DateFormat> DFS = new HashMap<String, DateFormat>();

    /**//from w  w  w.j  a va2s .c  om
     * @param source
     * @param pattern
     * @return Date
     */
    public static Date parse(String source, String pattern) {
        if (source == null) {
            return null;
        }
        Date date;
        try {
            date = getFormat(pattern).parse(source);
        } catch (ParseException e) {
            return null;
        }
        return date;
    }

    public static DateFormat getFormat(String pattern) {
        DateFormat format = DFS.get(pattern);
        if (format == null) {
            format = new SimpleDateFormat(pattern);
            DFS.put(pattern, format);
        }
        return format;
    }
}

Related

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