Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert String to Date  RSS feed

 
Death Arte
Greenhorn
Posts: 21
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • 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!
 
sri ramvaithiyanathan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to Ranch world.
check this Link and this Link

Regards,
Sriram.V
 
Joe carco
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@sri ramvaithiyanathan && Joe carco

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

Sorry for wrong posting..

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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 Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! it really works.. Applying KISS principle... Thank you Jesper de Jong!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!