Period.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
| Name | Description |
|---|---|
| Parse(ICharSequence) |
Obtains a Period from a text string such as PnYnMnD. |
| Parse(String) |
Parses a period of years, months, and days from a string. |
Parse(ICharSequence)
Obtains a Period from a text string such as PnYnMnD.
[Android.Runtime.Register("parse", "(Ljava/lang/CharSequence;)Ljava/time/Period;", "", ApiSince=26)]
public static Java.Time.Period? Parse(Java.Lang.ICharSequence? text);
[<Android.Runtime.Register("parse", "(Ljava/lang/CharSequence;)Ljava/time/Period;", "", ApiSince=26)>]
static member Parse : Java.Lang.ICharSequence -> Java.Time.Period
Parameters
- text
- ICharSequence
the text to parse, not null
Returns
the parsed period, not null
- Attributes
Remarks
Obtains a Period from a text string such as PnYnMnD. This will parse the string produced by toString() which is based on the ISO-8601 period formats PnYnMnD and PnW. The string starts with an optional sign, denoted by the ASCII negative or positive symbol. If negative, the whole period is negated. The ASCII letter "P" is next in upper or lower case. There are then four sections, each consisting of a number and a suffix. At least one of the four sections must be present. The sections have suffixes in ASCII of "Y", "M", "W" and "D" for years, months, weeks and days, accepted in upper or lower case. The suffixes must occur in order. The number part of each section must consist of ASCII digits. The number may be prefixed by the ASCII negative or positive symbol. The number must parse to an int. The leading plus/minus sign, and negative values for other units are not part of the ISO-8601 standard. In addition, ISO-8601 does not permit mixing between the PnYnMnD and PnW formats. Any week-based input is multiplied by 7 and treated as a number of days. For example, the following are valid inputs:
"P2Y" -- Period.ofYears(2)
"P3M" -- Period.ofMonths(3)
"P4W" -- Period.ofWeeks(4)
"P5D" -- Period.ofDays(5)
"P1Y2M3D" -- Period.of(1, 2, 3)
"P1Y2M3W4D" -- Period.of(1, 2, 25)
"P-1Y2M" -- Period.of(-1, 2, 0)
"-P1Y2M" -- Period.of(-1, -2, 0)
Java reference for java.time.Period.parse.
Applies to
Parse(String)
Parses a period of years, months, and days from a string.
public static Java.Time.Period? Parse(string? text);
static member Parse : string -> Java.Time.Period
Parameters
- text
- String
The period text, for example P1Y2M3D.
Returns
The period represented by text.
Remarks
This string overload calls Parse(ICharSequence). The input format is based on ISO-8601 periods. Each parsed week contributes seven days to the result.