Here you can find the source of parseDate(String d)
Parameter | Description |
---|---|
d | the d |
public static Date parseDate(String d)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /**//from w ww. j a v a2s . c o m * parse date produced by DeID software in format **DATE[Oct 15 2007] 1453 . * * @param d the d * @return the date */ public static Date parseDate(String d) { SimpleDateFormat sd1 = new SimpleDateFormat("MMM d yyyy HH:mm"); SimpleDateFormat sd2 = new SimpleDateFormat("MMM d yyyy"); Pattern pt = Pattern .compile("\\*\\*DATE\\[([A-Za-z]+ \\d{1,2} \\d{4})\\](?:\\s(\\d{2})\\:?(\\d{2}))?"); Matcher mt = pt.matcher(d); if (mt.matches()) { String date = mt.group(1); String h = mt.group(2); String m = mt.group(3); try { if (h != null) { return sd1.parse(date + " " + h + ":" + m); } else { return sd2.parse(date); } } catch (ParseException ex) { } } return null; } }