Java Date Parse convertStringToDate(String s)

Here you can find the source of convertStringToDate(String s)

Description

convert String To Date

License

Apache License

Declaration

public static Date convertStringToDate(String s) 

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 {
    public static Date convertStringToDate(String s) {
        try {/*  w ww  .  jav a 2s.com*/
            SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date d;
            d = dateformat1.parse(s);
            return d;
        } catch (ParseException e) {

        }

        try {
            SimpleDateFormat dateformat1 = new SimpleDateFormat("yyyy-MM-dd");
            Date d;
            d = dateformat1.parse(s);
            return d;
        } catch (ParseException e) {
        }

        throw new RuntimeException("Date format:" + s + " is not supported");
    }
}

Related

  1. convertStringToDate(String dateText)
  2. convertStringToDate(String dateTime)
  3. convertStringToDate(String dateTime)
  4. convertStringToDate(String dt)
  5. convertStringToDate(String input)
  6. convertStringToDate(String str)
  7. convertStringToDate(String str, String pattern)
  8. convertStringToDate(String str_date)
  9. convertStringToDate(String strDate)