• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String to date conversion in java

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SimpleDateFomat line is wrong...
instead of passing actuall string to SimpleDateFormat,it should pass the pattern..

eg :-

 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic