Here you can find the source of getTime(String time)
public static Timestamp getTime(String time)
//package com.java2s; /*/* w w w.j a v a 2 s .c o m*/ * This file is part of BillMining. * * BillMining is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * BillMining 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. <http://www.gnu.org/licenses/> * * Author(s): * * ? 2015 Kasra Madadipouya <kasra@madadipouya.com> */ import java.sql.Timestamp; import java.text.SimpleDateFormat; public class Main { public static Timestamp getTime(String time) { Timestamp timestamp = null; try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); java.util.Date parsedDate = dateFormat.parse(time); timestamp = new java.sql.Timestamp(parsedDate.getTime()); } catch (Exception e) {//this generic but you can control another types of exception e.printStackTrace(); } return timestamp; } }