Check if a particular date and time is invalid in CSharp
Description
The following code shows how to check if a particular date and time is invalid.
Example
//w ww .j a v a2 s .c o m
using System;
public class MainClass{
public static void Main(String[] argv){
DateTime baseTime = new DateTime(2007, 3, 11, 1, 59, 0, DateTimeKind.Unspecified);
DateTime newTime;
TimeZoneInfo pstZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
for (int ctr = 0; ctr < 63; ctr++)
{
newTime = baseTime.AddMinutes(ctr);
Console.WriteLine("{0} is invalid: {1}", newTime, pstZone.IsInvalidTime(newTime));
}
}
}
The code above generates the following result.