Here you can find the source of parse(String source, String pattern)
Parameter | Description |
---|---|
source | a parameter |
pattern | a parameter |
public static Date parse(String source, String pattern)
//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; } }