Connecting Tech Pros Worldwide Forums | Help | Site Map

Need to convert String to date(yyyy-mm-dd)

Newbie
 
Join Date: Oct 2006
Posts: 27
#1: Nov 27 '07
Hi,

I want to convert the string Sat Oct 25 00:00:00 GMT+05:30 2008 into yyyy-mm--dd fornat .
Can any one show me how.

Regards
Anil
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Nov 27 '07

re: Need to convert String to date(yyyy-mm-dd)


Quote:

Originally Posted by spooky

Hi,

I want to convert the string Sat Oct 25 00:00:00 GMT+05:30 2008 into yyyy-mm--dd fornat .
Can any one show me how.

Regards
Anil

Read the specs for the parse method of the DateFormat class. If that won't help then you may have to do some manual splitting. Is that the only date you want to parse or are there many dates that you want to parse? Are all of them going to be in this format?
Newbie
 
Join Date: Oct 2006
Posts: 27
#3: Nov 27 '07

re: Need to convert String to date(yyyy-mm-dd)


Hi
Thanks for replying... Am getting this date from the excel sheet using poi api. it returns date values in this format. Yes I have plenty dates all in the same format. I tried splitting it but it does'nt work .

Regards
Anil
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: Nov 27 '07

re: Need to convert String to date(yyyy-mm-dd)


Quote:

Originally Posted by spooky

Hi
Thanks for replying... Am getting this date from the excel sheet using poi api. it returns date values in this format. Yes I have plenty dates all in the same format. I tried splitting it but it does'nt work .

Regards
Anil

Don't try to fiddle around with that splitting first.
Read this.
Then have a look at this code

Expand|Select|Wrap|Line Numbers
  1. String pattern = "EEE MMM dd yyyy";
  2.     SimpleDateFormat df = new SimpleDateFormat(pattern);
  3.     try {
  4.         System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(df.parse("Sat Oct 25 2008")));
  5.  
  6.     }
  7.     catch(ParseException e) {
  8.         e.printStackTrace();
  9.     }
You should be able to do the rest.
Reply