Java String to Date StringToDate(String s)

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

Description

String To Date

License

Open Source License

Declaration

public static Date StringToDate(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.ParsePosition;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String PATTERN_YMDHMS = "yyyy-MM-dd HH:mm:ss";

    public static Date StringToDate(String s) {
        Date date = new Date();
        try {//w ww  . j  a  v a  2 s.com
            SimpleDateFormat simpledateformat = new SimpleDateFormat(PATTERN_YMDHMS);
            ParsePosition parseposition = new ParsePosition(0);
            date = simpledateformat.parse(s, parseposition);
        } catch (Exception ex) {
        }
        return date;
    }

    public static Date StringToDate(String s, String reg) {
        Date date = new Date();
        try {
            SimpleDateFormat simpledateformat = new SimpleDateFormat(reg);
            ParsePosition parseposition = new ParsePosition(0);
            date = simpledateformat.parse(s, parseposition);
        } catch (Exception ex) {
        }
        return date;
    }
}

Related

  1. StringToDate(String fecha)
  2. stringToDate(String fecha, String formato)
  3. StringToDate(String format, String dateStr)
  4. stringToDate(String input)
  5. stringToDate(String pstrValue, String pstrDateFormat)
  6. stringToDate(String s)
  7. stringToDate(String s)
  8. StringToDate(String s)
  9. stringToDate(String s, DateFormat formatter)