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 to convert string to double in java
how to convert string to double in java
how to convert string to double in java
How to convert String to int in Java
How to convert String to int in Java
How to convert String to int in Java
How to convert String to int in Java
How ro convert char into string??
How to convert date to string in Java?
How to convert Arraylist into String Array Java
how to convert string to char array in Java
How to convert Input Stream to String in java
Please tell me how can i convert string to timer
How to convert a stack trace to a string?
How to convert a stack trace to a string?
How ro convert char into string using recursive function in c#??
how to convert string to char array in java without using tochararray
How to convert date to string in Java in yyyy-mm-dd format
How to convert string to date in java in yyyy-mm-dd format?
convert string to date nsdate
Convert String into date
Convert String to Number
Read/Convert an inputStream to a String
How to convert String Date to Timestamp in Java?

Ads