none
Daylight Saving and .NET 1.1 RRS feed

  • Question

  • Hello,

     

    I'm having a problem with a software of mine that runs calculations for every hour of every day. The software works in UTC time how ever the data is localtime related. Problem occurs when there is extra hour.

     

    Is there a method or variable that would return me either if this is the daylight saving day or the daylight saving hour.

    I need to be able to skipt the extra hour. Any ideas?

    Thursday, March 6, 2008 10:39 AM

Answers

  • In .NET 2.0, the DateTime data type has an "IsDaylightSavingsTime" property.  Just set the variable to the date in question and check the property.

    Code Snippet

    Sub Main()
        TestDST(#3/8/2007#)
        TestDST(#3/9/2007#)

        TestDST(#3/10/2007#)
        TestDST(#4/30/2007#)
        TestDST(#3/8/2008#)
        TestDST(#3/9/2008#)

        TestDST(#3/10/2008#)
        TestDST(#4/30/2008#)
        Stop
    End Sub


    Private Sub TestDST(ByVal Value As DateTime)
        Console.WriteLine(Value.ToString & "  " & _
            Value.IsDaylightSavingTime.ToString)
    End Sub

     

     

     

    3/8/2007 12:00:00 AM  False
    3/9/2007 12:00:00 AM  False
    3/10/2007 12:00:00 AM  False
    4/30/2007 12:00:00 AM  True
    3/8/2008 12:00:00 AM  False
    3/9/2008 12:00:00 AM  False
    3/10/2008 12:00:00 AM  True
    4/30/2008 12:00:00 AM  True

     

     

    Thursday, March 6, 2008 1:50 PM

All replies

  • In .NET 2.0, the DateTime data type has an "IsDaylightSavingsTime" property.  Just set the variable to the date in question and check the property.

    Code Snippet

    Sub Main()
        TestDST(#3/8/2007#)
        TestDST(#3/9/2007#)

        TestDST(#3/10/2007#)
        TestDST(#4/30/2007#)
        TestDST(#3/8/2008#)
        TestDST(#3/9/2008#)

        TestDST(#3/10/2008#)
        TestDST(#4/30/2008#)
        Stop
    End Sub


    Private Sub TestDST(ByVal Value As DateTime)
        Console.WriteLine(Value.ToString & "  " & _
            Value.IsDaylightSavingTime.ToString)
    End Sub

     

     

     

    3/8/2007 12:00:00 AM  False
    3/9/2007 12:00:00 AM  False
    3/10/2007 12:00:00 AM  False
    4/30/2007 12:00:00 AM  True
    3/8/2008 12:00:00 AM  False
    3/9/2008 12:00:00 AM  False
    3/10/2008 12:00:00 AM  True
    4/30/2008 12:00:00 AM  True

     

     

    Thursday, March 6, 2008 1:50 PM
  • .Net 1.1 that I am currently using has method TimeZone.IsDaylightSavingTime I don't know how to use this
    TimeZone.IsDaylightSavingTime(time as date, daylighttimes as system.globalization.daylightTime) as boolean
    I don't know what to give for the DaylightTimes.
    Friday, March 7, 2008 5:59 AM