By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,011 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

How to restrict application at a specific time in specific timezone

100+
P: 111
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.

Expand|Select|Wrap|Line Numbers
  1. DateTime dt = DateTime.Now.To.ToUniversalTime();
  2.  //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.

Expand|Select|Wrap|Line Numbers
  1.  if (DateTime.Now.IsDaylightSavingTime()) //DayLight Saving Time True
  2.         {
  3.             return dt.AddHours(-4);
  4.         }
  5. else
  6.        {
  7.             return dt.AddHours(-5);
  8.  
  9.        }  
Note: IsDayLightSavingTime() 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
Apr 6 '10 #1
Share this Article
Share on Google+
2 Comments


tlhintoq
Expert 2.5K+
P: 3,525
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
Apr 6 '10 #2

100+
P: 111