Java SQL Time Parse stringToTime(String data, String dateFormat)

Here you can find the source of stringToTime(String data, String dateFormat)

Description

StringToDate Convert String to Timestamp

License

Open Source License

Parameter

Parameter Description
String dateFormat

Return

Timestamp

Declaration

public static Timestamp stringToTime(String data, String dateFormat) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Product: OSeB http://code.google.com/p/oseb                                *
 * Copyright (C) 2012 Mario Grigioni                                          *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program is distributed in the hope   *
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
 * See the GNU General Public License for more details.                       *
 * You should have received a copy of the GNU General Public License along    *
 * with this program; if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 *****************************************************************************/

import java.sql.Timestamp;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;

public class Main {
    /**************************************************************************
     *    StringToDate/*from w w  w  .  j av  a  2s  . c om*/
     *  Convert String to Timestamp
     *  @param String dataFormatada
     *  @param String dateFormat
     *    @return Timestamp
     */
    public static Timestamp stringToTime(String data, String dateFormat) {

        if (data == null || data.isEmpty())
            return null;

        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
        ParsePosition pos = new ParsePosition(0);
        java.util.Date date = null;
        Timestamp timestamp = null;

        date = formatter.parse(data, pos);
        timestamp = new Timestamp(date.getTime());
        return timestamp;
    }
}

Related

  1. parseTime(String str)
  2. parseTime(String timeString)
  3. printTime(Time time, String format)
  4. string2Time(String dateString)
  5. string2Time(String time, DateFormat timeFormat)
  6. stringToTime(String schedule)
  7. stringToTime(String sTime)
  8. StringToTime(String strDate)
  9. stringToTime(String timeString)