Export (0) Print
Expand All

SimpleDateFormat.parse Method (String, ParsePosition)

Visual Studio 2005

Parses a string into a Date object.

Package: java.text

Assembly: vjslib (in vjslib.dll)

public java.util.Date parse(
    java.lang.String sourceStr,
    java.text.ParsePosition pos);



The string to be parsed into a Date object.


Used to indicate the first position in the string to be parsed.

A Date object containing the date represented by the string.

The following example shows how to parse a date that adheres to a previously defined pattern.

// simpledateformat_parse.jsl

import java.text.*;
import java.util.Date;

public class Program
    public static void main(String[] args)
        // Create a SimpleDateFormat object.
        String pattern = "dd-MMM-yyyy HH:mm:ss.SSS";
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);

        // Parse a sample date starting at position 0.
        String sampleDateStr = "04-Jul-1776 22:00:00.000";
        ParsePosition pos = new ParsePosition(0);
        Date sampleDate = sdf.parse(sampleDateStr, pos);
        // Print out the date using the supplied pattern.

Sample Output:
04-Jul-1776 22:00:00.000

Community Additions

© 2014 Microsoft