Time.Parse(String) Method

Definition

Parses a date-time string in either the RFC 2445 format or an abbreviated format that does not include the "time" field.

[Android.Runtime.Register("parse", "(Ljava/lang/String;)Z", "GetParse_Ljava_lang_String_Handler")]
public virtual bool Parse (string? s);
[<Android.Runtime.Register("parse", "(Ljava/lang/String;)Z", "GetParse_Ljava_lang_String_Handler")>]
abstract member Parse : string -> bool
override this.Parse : string -> bool

Parameters

s
String

the string to parse

Returns

true if the resulting time value is in UTC time

Attributes

Exceptions

if s cannot be parsed.

Remarks

Parses a date-time string in either the RFC 2445 format or an abbreviated format that does not include the "time" field. For example, all of the following strings are valid:

<ul> <li>"20081013T160000Z"</li> <li>"20081013T160000"</li> <li>"20081013"</li> </ul>

Returns whether or not the time is in UTC (ends with Z). If the string ends with "Z" then the timezone is set to UTC. If the date-time string included only a date and no time field, then the allDay field of this Time class is set to true and the hour, minute, and second fields are set to zero; otherwise (a time field was included in the date-time string) allDay is set to false. The fields weekDay, yearDay, and gmtoff are always set to zero, and the field isDst is set to -1 (unknown). To set those fields, call #normalize(boolean) after parsing.

To parse a date-time string and convert it to UTC milliseconds, do something like this:

Time time = new Time();
              String date = "20081013T160000Z";
              time.parse(date);
              long millis = time.normalize(false);

Java documentation for android.text.format.Time.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.

Applies to