• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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: 43028
76
  • 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: 67682
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: 43028
76
  • 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 ]
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic