How to restrict application at a specific time in specific timezone

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharathreddy
    New Member
    • Aug 2006
    • 116

    How to restrict application at a specific time in specific timezone

    This is insight I would like to share how to restrict application from doing some tasks on specific time in specific timezone.

    Like if we want to restrict our application to work only from 12:01AM to 2:30PM EST and we don't know where the server is located and we don't know the timezone of the hosted application.

    Code:
    DateTime dt = DateTime.Now.To.ToUniversalTime();
     //This will convert the time to UTC
    Now we know the UTC time and we also know that EST = UTC-4 (with daylight saving time).

    And we also know that EST = UTC - 5 (without daylight saving time)

    So to get the current datetime in EST we do as bellow.

    Code:
     if (DateTime.Now.IsDaylightSavingTime()) //DayLight Saving Time True
            {
                return dt.AddHours(-4);
            }
    else
           {
                return dt.AddHours(-5);
    
           }
    Note: IsDayLightSavin gTime() is the function which returns boolean value weather the time is in DST or not.

    Here we get the datetime in EST. Using this datetime value we can write our custom logic to restrict the application from doing some specific tasks....

    Hope this helps some one. Please feel free to ask any questions on datetime issues.

    Thanks
    Bharath Reddy VasiReddy
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Like if we want to restrict our application to work only from 12:01AM to 2:30PM EST and we don't know where the server is located and we don't know the timezone of the hosted application.
    Why would we *not* know? Just ask the computer. That's what the TimeZone class in the framework is for.
    TimeZone class
    TimeZoneInfo class

    Comment

    • bharathreddy
      New Member
      • Aug 2006
      • 116

      #3
      Yes you are right....

      Comment

      Working...