Java Date Parse getDateFromFormattedDate(String dateStr, String format)

Here you can find the source of getDateFromFormattedDate(String dateStr, String format)

Description

get Date From Formatted Date

License

Open Source License

Declaration

public static Date getDateFromFormattedDate(String dateStr, String format) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    public static Date getDateFromFormattedDate(String dateStr, String format) {
        try {/*from  w  w w.j  av a2  s .c  om*/
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            if (dateStr != null && !"XXXX".equals(dateStr)) {
                Date date = sdf.parse(dateStr);
                return date;
            }
        } catch (ParseException pe) {
            System.out.println("Exception: " + pe);
        }
        return new Date(0);
    }
}

Related

  1. getDateFromDatestamp(String datestamp)
  2. getDateFromDateTimeUTCFormat(final String dateString)
  3. getDateFromDCItemTimestamp(String dateTimeStamp)
  4. getDateFromFileName(String fileName)
  5. getDateFromFormat(Date date, String type)
  6. getDateFromFormattedTimeStamp( String formattedTimeStamp)
  7. getDateFromIRODSValue(final String irodsValue)
  8. getDateFromISO8601(Object iso8601)
  9. getDateFromISO8601(String dateString)