Java Timestamp Create getTimestamp(String str)

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

Description

get Timestamp

License

Apache License

Declaration

public static Timestamp getTimestamp(String str) 

Method Source Code

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

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;

public class Main {
    public static Timestamp getTimestamp(String str) {
        try {/*from w  ww . j  a  v  a2  s  . co m*/
            if (str == null || str.equals("")) {
                return null;
            }
            if (str.length() == 10) {
                DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");// DateFormat.getDateInstance(DateFormat.MEDIUM,
                // java.util.Locale.CHINA);
                java.util.Date tempDate = df.parse(str);
                return new java.sql.Timestamp(tempDate.getTime());
            }
            DateFormat df = DateFormat.getDateTimeInstance();
            java.util.Date tempDate = df.parse(str);
            return new java.sql.Timestamp(tempDate.getTime());
        } catch (ParseException ex) {
            return null;
        }
    }
}

Related

  1. getTimestamp(ResultSet rs, String strColName)
  2. getTimestamp(String date, String time)
  3. getTimestamp(String dateStr)
  4. getTimestamp(String dateString, String format)
  5. getTimestamp(String sqlDateTime)
  6. getTimestamp(String Str)
  7. getTimestamp(String strDate)
  8. getTimestamp(String time, String pattern)
  9. getTimestamp2()