Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to date conversion in java

 
Pallavi Kulkarni
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have my date in string format and I want to convert it into date format. I also tried toDate(String) function. But it is not giving result. And I also tried following code:

SimpleDateFormat formatter=new SimpleDateFormat(text3);
java.sql.Date effect_from=new java.sql.Date( formatter.parse(text3).getTime());
java.sql.Date end_on = new java.sql.Date(formatter.parse(text3).getTime());


In above code when I try to print 'effect_from'it prints any random date.
So please tell me solution.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The SimpleDateFormat constructor doesn't take the text to be parsed as argument, it takes the format description as argument. See the javadocs of the SimpleDateFormat class for a lengthy explanation of the available formats.
 
Amit Y Desai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SimpleDateFomat line is wrong...
instead of passing actuall string to SimpleDateFormat,it should pass the pattern..

eg :-

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on HTML.

This post has been moved to a more appropriate forum.
 
Amit Y Desai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Bear Bibeault ,

i thing this post belongs to correct topic..as string to date conversion comes under "java in general"...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Y Desai:
SimpleDateFomat line is wrong...
instead of passing actuall string to SimpleDateFormat,it should pass the pattern..

eg :-


Note that "mm/dd/yyyy" means most likely not what you think it means. "mm" is minutes, not months. Use "MM" for months. See the API documentation of class SimpleDateFormat for documentation about the format string.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Y Desai:
i thing this post belongs to correct topic..as string to date conversion comes under "java in general"...

It was originally posted in the HTML forum, here, that's why that post is there.

You will see many such messages as unfortunately it's a common phenomenon that people post topics into unrelated forums.
 
vikram veera
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find the code in the below URL
http://developerparadise.com/devworld/Faqs/2007/Java/3Collection/JavaCollectionFaqs_3_Integerate.php#q0

[ February 22, 2008: Message edited by: vikram veera ]
[ February 22, 2008: Message edited by: vikram veera ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic