Java SQL Date Parse parseDate(String exifDate)

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

Description

parse Date

License

Apache License

Declaration

public static Date parseDate(String exifDate) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static Date parseDate(String exifDate) {
        if (exifDate == null) {
            return null;
        }//from  w  w w  .j  av a2  s.c  o m
        String patterns[];
        int i;
        patterns = (new String[] { "yyyy:MM:dd HH:mm:ss", "yyyy:MM:dd HH:mm", "yyyy-MM-dd HH:mm:ss",
                "yyyy-MM-dd HH:mm", "dd.MM.yy HH:mm", "yyyyMMdd HHmmss", "yyyyMMdd.HHmmss", "yyyyMMdd HHmm",
                "MM/dd/yy hh:mm a", "HH:mm:ss dd.MM.yyyy", "yyyy:MM:dd", "yyyy-MM-dd", "dd.MM.yy", "yyyyMMdd",
                "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "MM/dd/yy", "yyyy:MM:dd HH:mm:sss" });
        for (i = 0; i < patterns.length; i++) {
            try {
                DateFormat parser = new SimpleDateFormat(patterns[i]);
                return parser.parse(exifDate);
            } catch (ParseException ex) {
            }
        }
        return null;
    }

    public static Date parseDate(String date, String pattern) {
        if (date == null)
            return null;

        try {
            DateFormat parser = new SimpleDateFormat(pattern);
            return parser.parse(date);
        } catch (ParseException ex) {
        }

        return null;
    }

    public static String parseDate(Timestamp timestamp, String pattern) {
        if (timestamp == null)
            return null;

        DateFormat parser = new SimpleDateFormat(pattern);
        return parser.format(timestamp);
    }
}

Related

  1. getSqlDateFromString(String dateAsString, String format)
  2. parse(String date)
  3. parseDate(final String dateString)
  4. parseDate(String date)
  5. parseDate(String dateStr, String formatStr)
  6. parseDate(String s)
  7. parseDate(String s)
  8. parseDate(String strDate)
  9. parseDate(String strFormat, String dateValue)