How to Convert String to Date?

Ads
 

How to Convert String to Date?

Hi,

I am new in Java and learning the Date manipulation in Java. I have to write a program in Java which converts the String into Date object. My user enters the date into input field and now I have to convert it to Date object.

Tell me How to Convert String to Date?

Thanks

View Answers

January 4, 2014 at 10:24 PM

Hi Dude,

Its very easy to convert the String into date format. There is a class SimpleDateFormat which already available in the JDK which you can use for converting the String representation of date into real Date object.

You can use the following code:

  formatter = new SimpleDateFormat("dd-MMM-yy");
  date = (Date)formatter.parse(str_date);

The parse() method of the SimpleDateFormat class returns the date object.

Read more at Convert String to Date.

Thanks

Ads









Related Tutorials/Questions & Answers:
How to convert into to String in Java?
How to convert a String to an int?
Advertisements
How to Convert String to Date?
How to convert String into java.util.Date
How to convert string to byte in Java
how to convert string to image in java
how to convert string to double in java
How ro convert char into string??
How to convert Arraylist into String Array Java
How to convert String double quotos to String double double quotes(
How to convert Input Stream to String in java
how to convert xml string to soap request object using axis1.4?
Please tell me how can i convert string to timer
How ro convert char into string using recursive function in c#??
Java convert string to InputStream
Convert String into date
convert string to date nsdate
How to convert string to date in java in yyyy-mm-dd format?
Convert charArray to String
Convert Number to String
Convert String to Number
Convert Array to String
Convert Character into a String
Comparing two dates in java
Convert String to a float
Convert string into character array
Convert a String to Hexa
Read/Convert an inputStream to a String
Convert String to long
How to convert String Date to Timestamp in Java?
How to Convert ArrayList to Array?

Ads