Java Timestamp Parse stringToTimestamp(String sTimestamp)

Here you can find the source of stringToTimestamp(String sTimestamp)

Description

string To Timestamp

License

Open Source License

Declaration

public static Timestamp stringToTimestamp(String sTimestamp) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

public class Main {

    public static Timestamp stringToTimestamp(String sTimestamp) throws Exception {
        Date d;//from  w  w  w . j  a  v a  2s .  c  om
        SimpleDateFormat stringToDate;
        try {
            stringToDate = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.S");
            d = stringToDate.parse(sTimestamp);
        } catch (ParseException e) {
            stringToDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
            d = stringToDate.parse(sTimestamp);
        }
        return new Timestamp(d.getTime());
    }
}

Related

  1. stringToTimestamp(final String dateString)
  2. stringToTimestamp(String aS_Timestamp, String aS_Format, Timestamp aTs_ValidStart, Timestamp aTs_ValidEnd)
  3. stringToTimestamp(String date, String formatStr)
  4. stringToTimeStamp(String dateTimeString, String dateTimeFormat, TimeZone tz, Locale locale)
  5. stringToTimestamp(String marcTimestamp)
  6. stringToTimestamp(String ts)
  7. stringToTimestamp(String value)
  8. stringToTimesTamp(String yMd, boolean isEndTime)
  9. stripToMinutes(java.sql.Timestamp timestamp)