Here you can find the source of convertSQLTimestamp(String s, String formatIn, String formatOut)
public static java.sql.Timestamp convertSQLTimestamp(String s, String formatIn, String formatOut)
//package com.java2s; /* $This file is distributed under the terms of the license in /doc/license.txt$ */ import java.text.ParsePosition; import java.text.SimpleDateFormat; public class Main { /**//from ww w . j av a 2 s . co m * returns a SQL Timestamp given a formatted string */ public static java.sql.Timestamp convertSQLTimestamp(String s, String formatIn, String formatOut) { String s2 = convertStringDate(s, formatIn, formatOut); //System.out.println("s2: "+s2); return java.sql.Timestamp.valueOf(s2 + ".0"); } /** * given a String date in a described format (i.e. YYYY-mm-dd) convert * it to a String date in a new format (i.e. MM-dd-YYYY) * * @param s input date string * @param formatin a format string * @param formatout a format string * @return formated date string */ public static String convertStringDate(String s, String formatIn, String formatOut) { try { if (s.equals("now")) { return (new SimpleDateFormat(formatOut).format(new java.util.Date())); } else { return (new SimpleDateFormat(formatOut)) .format((new SimpleDateFormat(formatIn)).parse(s, new ParsePosition(0))); } } catch (Exception e) { return ""; } } }