Java String to Date toDate(String dateValue, String format)

Here you can find the source of toDate(String dateValue, String format)

Description

to Date

License

Open Source License

Declaration

public static final Date toDate(String dateValue, String format) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {

    public static final Date toDate(String dateValue, String format) {
        Date value = null;/*from w  ww. ja  v a 2  s . co  m*/
        try {
            value = newDateFormat(format).parse(dateValue);
        } catch (Exception e) {
            // ignore
        }

        return value;
    }

    public static final DateFormat newDateFormat(String format) {
        return new SimpleDateFormat(format, Locale.getDefault());
    }

    public static final DateFormat newDateFormat(String format, Locale locale) {
        return new SimpleDateFormat(format, locale);
    }
}

Related

  1. toDate(String dateString, String dateFormatPattern)
  2. toDate(String dateString, String format)
  3. toDate(String datetime)
  4. toDate(String dateToConvert)
  5. toDate(String dateToDatify)
  6. toDate(String format, String str)
  7. toDate(String formatDate, String stringDate)
  8. toDate(String param)
  9. toDate(String patten, String value)