System.Globalization.DateTimeFormatInfo.TimeSeparator Property

Gets or sets the string that separates the components of time, that is, the hour, minutes, and seconds.

Syntax

public string TimeSeparator { get; set; }

Value

The string to use to separate the components of time; that is, the hour, the minutes and the seconds.

Exceptions

TypeReason
ArgumentNullExceptionThe value specified for a set operation is a null reference.
InvalidOperationExceptionThe current instance is read-only and a set operation was attempted.

Remarks

If the custom pattern includes the format pattern ":", DateTime.ToString displays the value of DateTimeFormatInfo.TimeSeparator in place of the ":" in the format pattern.

The time separator is derived from the DateTimeFormatInfo.ShortTimePattern property. We recommend that you set the time separator in short or long time patterns to an exact string instead of using the time separator placeholder. For example, to obtain the pattern h-mm-ss, set the pattern to "h-mm-ss". This practice also enables you to set patterns such as "h'h 'mm'm 'ss's'" (3h 36m 12s) that include multiple types of separators. The DateTimeFormatInfo.TimeSeparator property defines the string that replaces the time separator (":" custom date and time format specifier) in a result string in a formatting operation. It also defines the time separator string in a parsing operation.

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0