Here you can find the source of parseDateTime(String dateTimeString, String[] validFormats, String outputFormat)
public static String parseDateTime(String dateTimeString, String[] validFormats, String outputFormat)
//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; } }