Java Timestamp Parse string2Timestamp(String strDateTime, String pattern)

Here you can find the source of string2Timestamp(String strDateTime, String pattern)

Description

string Timestamp

License

Open Source License

Declaration

public static Timestamp string2Timestamp(String strDateTime, String pattern) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String PATTERN_STANDARD = "yyyy-MM-dd HH:mm:ss";

    public static Timestamp string2Timestamp(String strDateTime, String pattern) {
        if (strDateTime == null || strDateTime.equals("")) {
            throw new java.lang.IllegalArgumentException("Date Time Null Illegal");
        }//  w w w.ja  va 2 s.co m
        if (pattern == null || pattern.equals("")) {
            pattern = PATTERN_STANDARD;
        }

        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        Date date = null;
        try {
            date = sdf.parse(strDateTime);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return new Timestamp(date.getTime());
    }
}

Related

  1. parseTimestampToString(Timestamp stamp, String dateFormat)
  2. parseToDate(String timestamp, String pattern)
  3. str2Timestamp(String str)
  4. String2Timestamp(String date)
  5. String2Timestamp(String s, String fmt)
  6. String2Timestamp(String strInputDate)
  7. string2Timestamp(String value)
  8. stringToTimestamp()
  9. stringToTimestamp(final String dateString)