Java Timestamp Parse parseTimestamp(String strDate)

Here you can find the source of parseTimestamp(String strDate)

Description

parse Timestamp

License

Apache License

Declaration

public static final Timestamp parseTimestamp(String strDate) 

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 final Timestamp parseTimestamp(String strDate) {
        try {// ww  w .  j a  va  2s .  com
            // Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
            Timestamp result = Timestamp.valueOf(strDate);
            return result;
        } catch (Exception pe) {
            return null;
        }
    }

    /**
      * @param strDate
      * @param format
      * @return
      */
    public static final Timestamp parseTimestamp(String strDate, String pattern) {
        Date date = null;
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
            date = dateFormat.parse(strDate);
            return new Timestamp(date.getTime());
        } catch (Exception pe) {
            return null;
        }
    }
}

Related

  1. parseTimestamp(String pattern, String dateTime)
  2. parseTimestamp(String s)
  3. parseTimestamp(String s)
  4. parseTimestamp(String sDate, String sFormat)
  5. parseTimestamp(String src, String pattern)
  6. parseTimestamp(String time)
  7. parseTimestamp(String timestamp)
  8. parseTimeStamp(String timeStamp)
  9. parseTimestamp(String timestamp)