DateFormat.Parse Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
Parse(String, ParsePosition) |
Parses a date/time string according to the given parse position. |
Parse(String, Calendar, ParsePosition) |
Parses a date/time string according to the given parse position. |
Parse(String) |
Parses a date/time string. |
Parse(String, ParsePosition)
Parses a date/time string according to the given parse position.
[Android.Runtime.Register("parse", "(Ljava/lang/String;Ljava/text/ParsePosition;)Ljava/util/Date;", "GetParse_Ljava_lang_String_Ljava_text_ParsePosition_Handler", ApiSince=24)]
public virtual 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", ApiSince=24)>]
abstract member Parse : string * Java.Text.ParsePosition -> Java.Util.Date
override this.Parse : string * Java.Text.ParsePosition -> Java.Util.Date
Parameters
- text
- String
The date/time string to be parsed
- pos
- ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
Returns
A Date, or null if the input could not be parsed
- Attributes
Remarks
Parses a date/time string according to the given parse position. For example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date that is equivalent to Date(837039928046).
By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
Note that the normal date formats associated with some calendars - such as the Chinese lunar calendar - do not specify enough fields to enable dates to be parsed unambiguously. In the case of the Chinese lunar calendar, while the year within the current 60-year cycle is specified, the number of such cycles since the start date of the calendar (in the ERA field of the Calendar object) is not normally part of the format, and parsing may assume the wrong era. For cases such as this it is recommended that clients parse using the parse method that takes a Calendar with the Calendar passed in set to the current date, or to a date within the era/cycle that should be assumed if absent in the format.
Java documentation for android.icu.text.DateFormat.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
Parse(String, Calendar, ParsePosition)
Parses a date/time string according to the given parse position.
[Android.Runtime.Register("parse", "(Ljava/lang/String;Landroid/icu/util/Calendar;Ljava/text/ParsePosition;)V", "GetParse_Ljava_lang_String_Landroid_icu_util_Calendar_Ljava_text_ParsePosition_Handler", ApiSince=24)]
public abstract void Parse (string? text, Android.Icu.Util.Calendar? cal, Java.Text.ParsePosition? pos);
[<Android.Runtime.Register("parse", "(Ljava/lang/String;Landroid/icu/util/Calendar;Ljava/text/ParsePosition;)V", "GetParse_Ljava_lang_String_Landroid_icu_util_Calendar_Ljava_text_ParsePosition_Handler", ApiSince=24)>]
abstract member Parse : string * Android.Icu.Util.Calendar * Java.Text.ParsePosition -> unit
Parameters
- text
- String
The date/time string to be parsed
- cal
- Calendar
The calendar set on input to the date and time to be used for missing values in the date/time string being parsed, and set on output to the parsed date/time. In general, this should be initialized before calling this method - either cleared or set to the current date, depending on desired behavior. If this parse fails, the calendar may still have been modified. When the calendar type is different from the internal calendar held by this DateFormat instance, calendar field values will be parsed based on the internal calendar initialized with the time and the time zone taken from this calendar, then the parse result (time in milliseconds and time zone) will be set back to this calendar.
- pos
- ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
- Attributes
Remarks
Parses a date/time string according to the given parse position. For example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Calendar that is equivalent to Date(837039928046). Before calling this method the caller should initialize the calendar in one of two ways (unless existing field information is to be kept): (1) clear the calendar, or (2) set the calendar to the current date (or to any date whose fields should be used to supply values that are missing in the parsed date). For example, Chinese calendar dates do not normally provide an era/cycle; in this case the calendar that is passed in should be set to a date within the era that should be assumed, normally the current era.
By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
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
Parse(String)
Parses a date/time string.
[Android.Runtime.Register("parse", "(Ljava/lang/String;)Ljava/util/Date;", "GetParse_Ljava_lang_String_Handler", ApiSince=24)]
public virtual Java.Util.Date? Parse (string? text);
[<Android.Runtime.Register("parse", "(Ljava/lang/String;)Ljava/util/Date;", "GetParse_Ljava_lang_String_Handler", ApiSince=24)>]
abstract member Parse : string -> Java.Util.Date
override this.Parse : string -> Java.Util.Date
Parameters
- text
- String
The date/time string to be parsed
Returns
A Date, or null if the input could not be parsed
- Attributes
Remarks
Parses a date/time string. For example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date that is equivalent to Date(837039928046). Parsing begins at the beginning of the string and proceeds as far as possible. Assuming no parse errors were encountered, this function doesn't return any information about how much of the string was consumed by the parsing. If you need that information, use a version of parse() that takes a ParsePosition.
By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
Note that the normal date formats associated with some calendars - such as the Chinese lunar calendar - do not specify enough fields to enable dates to be parsed unambiguously. In the case of the Chinese lunar calendar, while the year within the current 60-year cycle is specified, the number of such cycles since the start date of the calendar (in the ERA field of the Calendar object) is not normally part of the format, and parsing may assume the wrong era. For cases such as this it is recommended that clients parse using the parse method that takes a Calendar with the Calendar passed in set to the current date, or to a date within the era/cycle that should be assumed if absent in the format.
Java documentation for android.icu.text.DateFormat.parse(java.lang.String)
.
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.