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

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

Description

string To Date

License

Open Source License

Declaration

public static Date stringToDate(String strDate, String pattern) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

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

import java.util.Date;

public class Main {
    private static final SimpleDateFormat DB_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");

    public static Date stringToDate(String strDate, String pattern) {
        Date date = null;/*from ww w  .jav a2s. com*/
        DateFormat df = new SimpleDateFormat(pattern);
        try {
            date = df.parse(strDate);
        } catch (ParseException e) {
            return null;
        }
        return date;
    }

    public static Date parse(Long date) {
        try {
            return DB_FORMAT.parse(String.valueOf(date));
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. stringToDate(String strDate)
  2. stringToDate(String strDate)
  3. stringToDate(String strDate)
  4. stringToDate(String strDate, String formartStr)
  5. stringToDate(String strDate, String oracleFormat)
  6. stringToDate(String strDate, String strFormat)
  7. stringToDate(String string)
  8. stringToDate(String string, String format)
  9. stringToDate(String text)