aspose file tools
The moose likes Beginning Java and the fly likes date format Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "date format" Watch "date format" New topic
Author

date format

Rajendra Nath
Greenhorn

Joined: Nov 09, 2005
Posts: 27
hi all,

SimpleDateFormat dateformat=new SimpleDateFormat("MM-dd-yyyy");
System.out.println("Formated date:"+dateformat.format(dd)); String parsedate=dateformat.format(dd);

which prints this output
Formated date:02-02-2007

i am also using the date picker in a jsp, which prints the date as 2-2-2007.
there is a problem with these date formats. date picker gives the date as 2-2-2007, but the java code gives the date prepending with 0.
can you please help me. as there is a problem with executing the sql query.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12953
    
    3

there is a problem with these date formats. date picker gives the date as 2-2-2007, but the java code gives the date prepending with 0.
can you please help me. as there is a problem with executing the sql query.

So can you please explain what you want exactly? Do you want Java to format the date without the leading zeroes? If that is what you want, then use the format "M-d-yyyy" instead of "MM-dd-yyyy".

What is the problem with the SQL query?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: date format
 
Similar Threads
date format
How to print default date in required format
Is this a bug?
error in formatting miliseconds for date objects
Date function