• 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
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Convert String to Date

 
Greenhorn
Posts: 21
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good day!

Im new here and i would like to ask a little help from you guys.
How to convert String to Date?

Code:



Eclipse display this error message:
Type mismatch: cannot convert from String to Date

i've read that everything found in google search but it still error.

PS: sorry for my Grammar.. Thank you and God bless you all!
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to Ranch world.
check this Link and this Link

Regards,
Sriram.V
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like your in the wrong Forum. Your question has nothing to do with Servlets.

Seems like youre confusing parsing and formatting. To format a date you need a Date and not a String. If you want to create a Date from a String try this:



if you want to format:

 
Death Arte
Greenhorn
Posts: 21
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@sri ramvaithiyanathan && Joe carco

Thank you very much! My problem has been solved..

Sorry for wrong posting..

 
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

Joe carco wrote:


The cast to Date is unnecessary; the parse() method already returns a Date object. Just write it like this:

You should avoid type casts as much as possible in your source code.
 
Death Arte
Greenhorn
Posts: 21
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow! it really works.. Applying KISS principle... Thank you Jesper de Jong!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic