Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Parse String in Date Format

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 256
    Comment on it

    In order to parse the String in date, first of all you need to check in which date format the String is coming. Then we will define date pattern accordingly.
    Following steps will guide you how to parse String in Date:-
    Step 1
    Understand the date format of String:-
    Example:-

    2015-11-20             ->  yyyy-MM-dd
    2015-11-22 12:55       ->  yyyy-MM-dd HH:mm
    

    Step 2
    Create instance of SimpleDateFormat. Suppose your string is coming in "yyyy-MM-dd" then define SimpleDateFormat like this:-

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    

    Step 3
    Parse that string using parse method of SimpleDateFormat class. Put this call in try catch as it can return ParseException

     try {
               Date date = simpleDateFormat.parse(dateString);
           } catch (ParseException e) {
                    e.printStackTrace();           
           }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: