Java SQL Time Format formatCharDateYMDHMS(String str)

Here you can find the source of formatCharDateYMDHMS(String str)

Description

format Char Date YMDHMS

License

Open Source License

Declaration

public static Date formatCharDateYMDHMS(String str) 

Method Source Code


//package com.java2s;
import java.sql.Date;

import java.text.*;

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

    public static Date formatCharDateYMDHMS(String str) {

        String format = DEFAULT_YMDHMSDATE_FORMAT;

        if (str == null || str.trim().length() == 0) {

            return null;
        }//  ww w  .  j  ava 2 s  . c om

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        ParsePosition pos = new ParsePosition(0);
        java.util.Date date = sdf.parse(str, pos);

        if (date == null) {

            return null;
        }

        return new Date(date.getTime());
    }
}

Related

  1. formatCharDateYMD(String str)
  2. formatDate(String Format)
  3. formatDateWithSlashes(java.sql.Date date)
  4. formatDateYM(Date date, String datePtn)
  5. formatDateYMD(String str, String datePtn)