Here you can find the source of getCurrentTime()
public static Timestamp getCurrentTime()
//package com.java2s; /*/*from ww w . j a v a 2s . com*/ * 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; import java.util.Calendar; public class Main { public static Timestamp getCurrentTime() { Calendar calendar = Calendar.getInstance(); java.util.Date now = calendar.getTime(); Timestamp currentTimestamp = new Timestamp(now.getTime()); return currentTimestamp; } 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; } }