Java String to Date stringToDate(String dateString, String pattern)

Here you can find the source of stringToDate(String dateString, String pattern)

Description

string To Date

License

Apache License

Declaration

public static Date stringToDate(String dateString, String pattern) 

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 stringToDate(String dateString) {
        return stringToDate(dateString, "yyyy-MM-dd HH:mm:ss");
    }/*from  w  w  w  .  ja v a  2  s.c  o  m*/

    public static Date stringToDate(String dateString, String pattern) {
        SimpleDateFormat simpledateformat = new SimpleDateFormat(pattern);
        Date date = new Date();
        try {
            date = simpledateformat.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

  1. stringToDate(String dateString)
  2. stringToDate(String dateString, String dataFormat)
  3. stringToDate(String dateString, String dateFormat)
  4. stringTodate(String dateString, String format)
  5. stringToDate(String dateString, String formatStr)
  6. stringToDate(String dateText, String format, boolean lenient)
  7. StringToDate(String Expression)
  8. StringToDate(String fecha)
  9. stringToDate(String fecha, String formato)