C# TimeZoneInfo IsInvalidTime
Description
TimeZoneInfo IsInvalidTime
indicates whether a particular
date and time is invalid.
Syntax
TimeZoneInfo.IsInvalidTime
has the following syntax.
public bool IsInvalidTime(
DateTime dateTime
)
Parameters
TimeZoneInfo.IsInvalidTime
has the following parameters.
dateTime
- A date and time value.
Returns
TimeZoneInfo.IsInvalidTime
method returns true if dateTime is invalid; otherwise, false.
Example
//from www . ja va 2 s . c o m
using System;
public class MainClass{
public static void Main(String[] argv){
// Specify DateTimeKind in Date constructor
DateTime baseTime = new DateTime(2007, 3, 11, 1, 59, 0, DateTimeKind.Unspecified);
DateTime newTime;
// Get Pacific Standard Time zone
TimeZoneInfo pstZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
// List possible invalid times for a 63-minute interval, from 1:59 AM to 3:01 AM
for (int ctr = 0; ctr < 63; ctr++)
{
// Because of assignment, newTime.Kind is also DateTimeKind.Unspecified
newTime = baseTime.AddMinutes(ctr);
Console.WriteLine("{0} is invalid: {1}", newTime, pstZone.IsInvalidTime(newTime));
}
}
}
The code above generates the following result.