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

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

Description

to Date

License

Open Source License

Declaration

public static Date toDate(String format, String str) 

Method Source Code


//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static SimpleDateFormat sdf = new SimpleDateFormat();

    public static Date toDate(String format, String str) {
        Date date = null;//from w ww . j  a v  a  2  s  .c  o  m
        if (format == null) {
            sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
        } else {
            sdf.applyPattern(format);
        }
        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

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