data convertion
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sathis_kumar
Posted On:   Friday, April 6, 2001 12:58 AM

how to convert string to date ?

Re: data convertion

Posted By:   Michael_Wax  
Posted On:   Friday, April 6, 2001 09:55 AM

The DateFormat and its subclasses have methods called "parse" which parse Strings into Dates.
For internationalization, you need to get the proper instance of DateFormat, as follows.


DateFormat myFormat = DateFormat.getDateInstance(DateFormat.LONG, myLocale);
Date date = myFormat.parse(dateString);

Several points:

  • You need to catch a ParseException

  • DateFormat.LONG
    is a constant specifying the length and format of the date string; see the DateFormat API for more details.

  • You can also use
    DateFormat.getDateTimeInstance
    or
    DateFormat.getTimeInstance
    depending on what you want your users to input.

  • You can find out what format the string should have in internationalized form by casting the DateFormat object to a SimpleDateFormat object, then applying the
    toLocalizedPattern
    method.

  • If you want more control over the format of the date string, you can use the SimpleDateFormat class, but then you need to handle more of the internationalization details yourself.

About | Sitemap | Contact