How to Convert String to Date?

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









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 into java.util.Date
How to Convert String to Date?
How to convert string to byte 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 image 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 string to char array in Java
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
ModuleNotFoundError: No module named 'datec'
ModuleNotFoundError: No module named 'datec'
Convert String into date
How to convert a stack trace to a string?
How to convert a stack trace to a string?
Java convert string to InputStream
Please tell me how can i convert string to timer
how to convert xml string to soap request object using axis1.4?
Convert charArray to String
Convert Number to 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 string to date in java in yyyy-mm-dd format?
convert string to date nsdate
Convert Array to String
How to convert date to string in Java in yyyy-mm-dd format
Convert String to Number
Read/Convert an inputStream to a String
Convert a String to Hexa
Convert Character into a String
Comparing two dates in java
Convert String to a float
Convert string into character array
Convert String to long
How to convert String Date to Timestamp in Java?
Convert String to Date
convert string type to mathod name
Convert ASCII to string
convert char to string objective c
Convert String to Class - JSP-Servlet

Ads