SimpleDateFormat.Parse(String, ParsePosition) Method

Definition

Parses text from a string to produce a Date.

[Android.Runtime.Register("parse", "(Ljava/lang/String;Ljava/text/ParsePosition;)Ljava/util/Date;", "GetParse_Ljava_lang_String_Ljava_text_ParsePosition_Handler")]
public override Java.Util.Date? Parse (string? text, Java.Text.ParsePosition? pos);
[<Android.Runtime.Register("parse", "(Ljava/lang/String;Ljava/text/ParsePosition;)Ljava/util/Date;", "GetParse_Ljava_lang_String_Ljava_text_ParsePosition_Handler")>]
override this.Parse : string * Java.Text.ParsePosition -> Java.Util.Date

Parameters

text
String

A String, part of which should be parsed.

pos
ParsePosition

A ParsePosition object with index and error index information as described above.

Returns

A Date parsed from the string. In case of error, returns null.

Attributes

Exceptions

if there are invalid characters in the pattern.

Remarks

Parses text from a string to produce a Date.

The method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed date is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed, the error index of pos is set to the index of the character where the error occurred, and null is returned.

This parsing operation uses the DateFormat#calendar calendar to produce a Date. All of the calendar's date-time fields are Calendar#clear() cleared before parsing, and the calendar's default values of the date-time fields are used for any missing date-time information. For example, the year value of the parsed Date is 1970 with GregorianCalendar if no year value is given from the parsing operation. The TimeZone value may be overwritten, depending on the given pattern and the time zone value in text. Any TimeZone value that has previously been set by a call to #setTimeZone(java.util.TimeZone) setTimeZone may need to be restored for further operations.

Java documentation for java.text.SimpleDateFormat.parse(java.lang.String, java.text.ParsePosition).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to