Java Hour Format formatStrToDate(String strDate, int format)

Here you can find the source of formatStrToDate(String strDate, int format)

Description

format Str To Date

License

Open Source License

Declaration

public final static java.util.Date formatStrToDate(String strDate, int format) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    private final static SimpleDateFormat[] DATE_FORMATTER = new SimpleDateFormat[] {
            new SimpleDateFormat("MMM d, yyy"), new SimpleDateFormat("EEE, MMM d, yyyy"),
            new SimpleDateFormat("MMM d, yyyy HH:mm:ss"), new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss"),
            new SimpleDateFormat("yyyy/MM/dd"), new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") };

    public final static java.util.Date formatStrToDate(String strDate, int format) {
        java.util.Date rel = null;
        if (strDate != null && !strDate.equals("")) {
            if (format >= DATE_FORMATTER.length || format < 0) {
                format = 0;//from   ww  w  . ja  v a 2  s .  c o m
            }
            try {
                rel = DATE_FORMATTER[format].parse(strDate);
            } catch (ParseException e) {
                rel = null;
            }
        }
        return rel;
    }
}

Related

  1. formatSQL(Date date)
  2. formatSqlDateTime(Date value)
  3. formatSSLValid(Date validFrom, Date validTo)
  4. formatStringTime(String dateTime)
  5. formatStringTimeToLong(String timeLine)
  6. formatStrToDate(String value, String pattern)
  7. formattedDate()
  8. formattedDate(java.util.Date date, String formatString)
  9. formattedDateToDate(String str)