Help on date parsing

Posted on 2009-12-16
Last Modified: 2013-12-22

 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.

Question by:vindys80
    LVL 40

    Expert Comment

    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

    LVL 92

    Expert Comment

    LVL 11

    Author Comment

    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.
    LVL 92

    Accepted Solution

    not possible really
    LVL 5

    Assisted Solution

    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.
    LVL 11

    Author Closing Comment


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

    Thanks for participating

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    classnotfoundexception 3 29
    matchUp  challenge 9 51
    mapShare challenge 13 41
    Modeling a class in java 5 24
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now