Java Timestamp from convertStringToTimeStamp(String date)

Here you can find the source of convertStringToTimeStamp(String date)

Description

convert String To Time Stamp

License

Apache License

Declaration

public static Timestamp convertStringToTimeStamp(String date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Timestamp;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

    public static Timestamp convertStringToTimeStamp(String date) {
        //19//  www.ja  va  2 s .c  om
        if (null == date || date.isEmpty()) {
            return null;
        }
        Timestamp ts = null;
        if (date.indexOf("/") != -1) {
            date = date.replace("/", "-");
        }
        try {
            SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date11 = df1.parse(date);
            String time = df1.format(date11);
            ts = Timestamp.valueOf(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ts;
    }
}

Related

  1. convertLongToTimestamp(Long millSec)
  2. convertSQLTimestamp(String s, String formatIn, String formatOut)
  3. convertString2TimeStamp(String dateString)
  4. convertString2Timestamp(String value)
  5. convertStringDateToTimestamp(String sDate, String dateformat)
  6. convertStringToTimestamp(String str)
  7. convertToTimestamp(Date aJavaDate)
  8. convertToTimestamp(java.util.Date date)
  9. convertToTimestamp(String dateData)