Java Parse Date parseDateTime(String dateTimeString, String[] validFormats, String outputFormat)

Here you can find the source of parseDateTime(String dateTimeString, String[] validFormats, String outputFormat)

Description

parse Date Time

License

Apache License

Declaration

public static String parseDateTime(String dateTimeString, String[] validFormats, String outputFormat) 

Method Source Code


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

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static String parseDateTime(String dateTimeString, String[] validFormats, String outputFormat) {
        for (int i = 0; i < validFormats.length; i++) {
            SimpleDateFormat format = new SimpleDateFormat(validFormats[i]);
            DateFormat df = new SimpleDateFormat(outputFormat);
            format.setLenient(false);//from w  w  w .  jav a 2 s .  c  om
            try {
                Date temp = format.parse(dateTimeString);
                if (temp != null) {
                    return df.format(temp);
                }
            } catch (ParseException e) {
            }
        }
        return null;
    }
}

Related

  1. parseDateTime(String date, String time)
  2. parseDateTime(String dateTime)
  3. parseDateTime(String dateTimeStr)
  4. parseDateTime(String dateTimeString)
  5. parseDateTime(String dateTimeString)
  6. parseDateTime(String format, String dateStr)
  7. parseDateTime(String fullDateParam, String unixDateParam, Map request)
  8. parseDateTime(String s)
  9. parseDateTime(String s)