I just began to study java language. I want to know How to convert String to Date object in java. Please help me.
I just began to study java language. I want to know How to convert String to Date object in java. Please help me.
1) Following code shows how to convert string to date:
import java.util.*;
import java.text.*;
public class StringToDate {
public static void main(String[] args) {
try { String str_date="18-January-10";
DateFormat formatter ;
Date date ;
formatter = new SimpleDateFormat("dd-MMM-yy");
date = (Date)formatter.parse(str_date);
System.out.println("Today is " +date );
} catch (ParseException e)
{System.out.println("Exception :"+e); }
}
}
Bookmarks