Java String to Date toDate(String date)

Here you can find the source of toDate(String date)

Description

to Date

License

Apache License

Declaration

public static Date toDate(String date) 

Method Source Code


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

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

public class Main {
    static SimpleDateFormat YYYY_DD_MM = new SimpleDateFormat("yyyy-MM-dd");
    static SimpleDateFormat YYYYDDMM = new SimpleDateFormat("yyyy/MM/dd");

    public static Date toDate(String date) {
        try {// w  w  w  .j  a v a 2s  .  co  m
            return YYYY_DD_MM.parse(date);
        } catch (ParseException e) {
            try {
                return YYYYDDMM.parse(date);
            } catch (ParseException e1) {
                return null;
            }
        }
    }
}

Related

  1. toDate(String d)
  2. toDate(String date)
  3. toDate(String date)
  4. toDate(String date)
  5. toDate(String date)
  6. toDate(String date)
  7. toDate(String date)
  8. toDate(String date, String dateFormat)
  9. toDate(String date, String format)