import java.text.SimpleDateFormat;
import java.util.Date;

public class StringtoDate {
    public static void main (String args[]){
        String inputDate = "04.11.2013 11:14:45 GMT 00:00";
        Date dat = convertStringToDate(inputDate);
    public static Date convertStringToDate(String inDate){
    SimpleDateFormat sdf = new SimpleDateFormat("mm.dd.yyyy hh24:mm:ss");
        Date date = new Date();
         try {
             date = sdf.parse(inDate);

         } catch (Exception e) {
         return date;

my input String is of type String ("04.11.2013 11:14:45 GMT 00:00"),
I m trying to convert to a type Date and which should be of foramt ("mm.dd.yyyy hh24:mi:ss") , and output of the DAte should look like ("3/7/2013 12:33:15.000000000 PM").
but i m getting exception ,

    java.text.ParseException: Unparseable date: "04.11.2013 11:14:45 GMT 00:00"
at StringtoDate.convertStringToDate(
at StringtoDate.main(

please help me to get the correct results.

Edited 3 Years Ago by ~s.o.s~: convert to discussion thread

The main issue is actually with your format string; for month, you should use capitalized letter M. Similarly, for 24-hour time going from 00 to 23, you need to use capital H. To get the time zone in the format you want, use the capital letter Z twice.

"MM.dd.yyyy HH:mm:ss ZZ"



would return Stringbuffer or string .
i need the format in DATE or timestamp

You seeem to be confused about the Date class.
A Date object represents an instant in time, and has methods to access it. It does NOT have a format. When you convert a Date to or from a String that's when a format is applied.

The main objective here is to pass my Date to Storedprocedure , where the stored procedure is mapped to Timestamp variable.

yeah i correct it, not the Date format . want it in Date object .

You have a String in a known format and you want to convert that to a Date object - yes?
If so your first code was the right approach. Did you fix the format specification as noted by Schol-R-LEA

if your main objective is to pass it to a stored procedure, pass it as is (meaning, as a string) and write the stored procedure in such a way that it does the conversion.
Much more efficient, as it eliminates the implicit conversion of a Java Date to a database date, and pushes the conversion to the database server, which typically is much better at such tasks (faster...) than the application server.

OK, thanks guys, tried using java.sql.timestamp , but still was not able to truncate the millisec from the timestamp object .
now changing the stored procedure .
if more doubts i ll start a new discussion about the stored procudure.

This question has already been answered. Start a new discussion instead.