Java Timestamp from convertStringDateToTimestamp(String sDate, String dateformat)

Here you can find the source of convertStringDateToTimestamp(String sDate, String dateformat)

Description

convert String Date To Timestamp

License

Apache License

Parameter

Parameter Description
date a parameter
dateformat a parameter

Return

Timestamp

Declaration

public static Timestamp convertStringDateToTimestamp(String sDate, String dateformat) 

Method Source Code


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

import java.sql.Timestamp;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /****//www. j a v a2s  .c  o m
     * 
     * @param date
     * @param dateformat
     * @return Timestamp
     */
    public static Timestamp convertStringDateToTimestamp(String sDate, String dateformat) {
        SimpleDateFormat dateFormat;
        Date date;
        Timestamp timestamp = null;
        try {
            dateFormat = new SimpleDateFormat(dateformat);
            date = dateFormat.parse(sDate);
            timestamp = new Timestamp(date.getTime());
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return timestamp;
    }
}

Related

  1. convertDateToTimestamp(java.util.Date date)
  2. convertLongToTimestamp(Long millSec)
  3. convertSQLTimestamp(String s, String formatIn, String formatOut)
  4. convertString2TimeStamp(String dateString)
  5. convertString2Timestamp(String value)
  6. convertStringToTimeStamp(String date)
  7. convertStringToTimestamp(String str)
  8. convertToTimestamp(Date aJavaDate)
  9. convertToTimestamp(java.util.Date date)