Java Timestamp Create getTimestampFromString(String dateString, String dateFormat)

Here you can find the source of getTimestampFromString(String dateString, String dateFormat)

Description

Trasform a date string into a timestamp

License

LGPL

Parameter

Parameter Description
dateString a parameter
dateFormat a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static Timestamp getTimestampFromString(String dateString, String dateFormat) throws ParseException 

Method Source Code

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

import java.sql.Timestamp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**/*  ww w  . j  av a  2s .  co m*/
     * Trasform a date string into a timestamp
     * @param dateString
     * @param dateFormat
     * @return
     * @throws ParseException
     */
    public static Timestamp getTimestampFromString(String dateString, String dateFormat) throws ParseException {

        SimpleDateFormat format = new SimpleDateFormat(dateFormat);
        Date parsedDate = format.parse(dateString);
        Timestamp ts = new Timestamp(parsedDate.getTime());
        return ts;
    }
}

Related

  1. getTimestampFromDate(Date d)
  2. getTimestampFromDate(String d)
  3. getTimestampFromDateTime(DateTime dateTime)
  4. getTimeStampFromISOString(String isoString)
  5. getTimestampFromString(String dateStr)
  6. getTimestampFromString(String id)
  7. getTimestampFromString(String s)
  8. getTimeStampFromString(String timeStamp)
  9. getTimestampInEnglish(java.sql.Timestamp t)