Java DateFormat parseObject() Example

DateFormat class parseObject() method example. This example shows you how to use parseObject() method.


Syntax is : public Object parseObject(String source, ParsePosition pos)
Method parses text from a string to produce a Date. The method attempts to parse text starting at the index given by pos.

Here is the code.
/**
 * @(#) ParseObjectDateFormat.java
 * A class representing use of method parseObject() of DateFormat
class in java.text Package.
 * @Version  13-May-2008
 @author   Rose India Team
 */
import java.util.*;
import java.text.*;

class ParseObjectDateFormat {

    public static void main(String[] argsthrows ParseException {

        // Create new Date object that will be initialized to the current date.
        Date date = new Date();
        System.out.println("Date  by  Date  class : " + date.toString());

        // Create object for default MEDIUM/SHORT DateFormat
        DateFormat dateFormat = DateFormat.getDateTimeInstance(
                DateFormat.MEDIUM, DateFormat.SHORT);

        // parse method call.
        ParsePosition pos = new ParsePosition(4);
        Object parseDate = dateFormat.parseObject("Sun Jan 1,2004 9:00 AM",pos);
        System.out.println("After parse  method   : " + parseDate.toString());
    }
}

Output of the program.
 

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US