Java Parse Date parseDate(String d)

Here you can find the source of parseDate(String d)

Description

parse date produced by DeID software in format **DATE[Oct 15 2007] 1453 .

License

Open Source License

Parameter

Parameter Description
d the d

Return

the date

Declaration

public static Date parseDate(String d) 

Method Source Code

//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;
    }
}

Related

  1. parseDate(String actual, DateFormat format, Pattern pattern)
  2. parseDate(String applyDt)
  3. parseDate(String buildDate, SimpleDateFormat dateFormat)
  4. parseDate(String certDate)
  5. parseDate(String currDate)
  6. parseDate(String d)
  7. parseDate(String d)
  8. parseDate(String datastr, String pattern)
  9. parseDate(String date)