Code example for SimpleDateFormat

Methods: parse

0
 
        // 
        // Create an instance of SimpleDateFormat with the specified 
        // format. 
        // 
        DateFormat sdf = new SimpleDateFormat("hh:mm:ss");
        try { 
            //  
            // The get the date object from the string just called the  
            // parse method and pass the time string to it. The method  
            // throws ParseException if the time string is in an  
            // invalid format. But remember as we don't pass the date  
            // information this date object will represent the 1st of 
            // january 1970. 
            Date date = sdf.parse(time);
            System.out.println("Date and Time: " + date);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    } 
}