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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version