2016-04-05 25 views
4

geçersiz bir zamanı temsil ediyor. Tarihin "3/13/2016 2:41:00 AM" olduğu bir durum var. Zaman dilimini tarihe göre değiştirdiğimde bir hata alıyorum.DateTime ayrıştırma hatası: Sağlanan DateTime,

DateTime dt = DateTime.Parse("3/13/2016 2:41:00 AM"); 
DateTime Date_Time = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, "Eastern Standard Time", 
                    "GMT Standard Time"); 
Response.Write(dt); 

idamından sonra, bu hatayı alıyorum: zaman belirsiz veya geçerli zaman olup olmadığını

The supplied DateTime represents an invalid time. For example, when the clock is adjusted forward, any time in the period that is skipped is invalid. Parameter name: dateTime

+5

Öyle ** tam istisna olarak ** mesaj açıklar. 13 Mart, EST'nin standarttan gün ışığından yararlanma saatine geçtiği gündü. Saat 2:41:00 yoktu, saat 2'den 3 AM'ye anında taşındığında atlandı. Yani geçtiğiniz değer sadece saçmalık. Çöp içeri çöp dışarı. –

cevap

6

deneyin kontrol etmek. Due to the daylight change, bahsettiğiniz saat, 2:41:00 AM, saat 1 saat ileri hareket edildiğinden ve bu nedenle tarih geçersiz veya belirsiz olduğundan mevcut değil.

2016 Sun, 13 Mar, 02:00 CST → CDT +1 hour (DST start) UTC-5h 
     Sun, 6 Nov, 02:00 CDT → CST -1 hour (DST end) UTC-6h 
Ayrıca bu blog bakabilirsiniz

: Zaman kullanabileceğiniz geçerli olup olmadığını System.TimeZoneInfo: Working with Ambiguous and Invalid Points in Time

System.TimeZoneInfo (currently available as part of .NET Framework 3.5 Beta 1) contains methods for checking if a DateTime instance represents an ambiguous or invalid time in a specific time zone. These methods are particularly useful for validating user-supplied points in time.

Background Information

Time zones that adjust their time for Daylight Saving Time (in most cases by moving the clock time back or forward by 1 hour) have gaps and repeats in the timeline — wherever the clock time was moved forward or back by the adjustment. Let’s use Pacific Standard Time as an example. In 2007 Pacific Standard Time (PST) changes to Pacific Daylight Time (PDT) at 02:00AM (“spring forward”) on the second Sunday in March and then returns at 02:00AM (“fall back”) on the first Sunday in November

kontrol etmek için:

TimeZoneInfo.IsInvalidTime