Java Timestamp Create getTimestampFromString(String dateStr)

Here you can find the source of getTimestampFromString(String dateStr)

Description

get Timestamp From String

License

Open Source License

Declaration

public static java.sql.Timestamp getTimestampFromString(String dateStr) 

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 static java.sql.Timestamp getTimestampFromString(String dateStr) {
        if (dateStr == null || dateStr.equals("")) {
            return null;
        }/*from w  w w.ja v a  2  s.c  o  m*/
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(dateStr, pos);
        if (strtodate == null) {
            strtodate = new Date();
        }
        return new java.sql.Timestamp(strtodate.getTime());

    }

    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        String min;
        min = dateString.substring(14, 16);
        return min;
    }
}

Related

  1. getTimestampFormatter()
  2. getTimestampFromDate(Date d)
  3. getTimestampFromDate(String d)
  4. getTimestampFromDateTime(DateTime dateTime)
  5. getTimeStampFromISOString(String isoString)
  6. getTimestampFromString(String dateString, String dateFormat)
  7. getTimestampFromString(String id)
  8. getTimestampFromString(String s)
  9. getTimeStampFromString(String timeStamp)