• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Help on date parsing

Hi,

 Given a date string like 11/13/2009 , Friday, November 27, 2009, How do I get its valid java format string... like for first string format is MM/DD/YYYY.

Thanks,
Vindys
0
vindys80
Asked:
vindys80
2 Solutions
 
Gurvinder Pal SinghCommented:
See the attached code

You just have to do the opposite of that



import java.text.SimpleDateFormat;
import java.util.Date;
 
public class Test4 
{
	public static void main(String[] args) throws Exception
	{
 
		String date = "Friday, November 27, 2009";
		
		SimpleDateFormat format = new SimpleDateFormat("EEEEE, MMMMM d, yy");
		
	    Date date1 = format.parse(date);
 
		SimpleDateFormat format2 = new SimpleDateFormat("MM/dd/yyyy");
	    
		System.out.println( format2.format(date1) );
	}
}

Open in new window

0
 
vindys80Author Commented:
I am sorry. I know how to change the format and to create date using parse too. What I need is like if i give a date string, I should be able to find the date format string for that date string.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
not possible really
0
 
josephtsangCommented:
The parser cannot handle ambigious cases, e.g 11/13/2009 can be intepreted by dd/mm/yyyy or mm/dd/yyyy. Both cases are valid.
0
 
vindys80Author Commented:

Anyway as you said its kinda hard to make such a parser itself.

Thanks for participating
Vindys
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now