Here you can find the source of stringToTime(String data, String dateFormat)
Parameter | Description |
---|---|
String | dateFormat |
public static Timestamp stringToTime(String data, String dateFormat)
//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; } }