471,107 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 471,107 developers and data experts.

How to restrict application at a specific time in specific timezone

111 100+
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
2 2927
tlhintoq
3,525 Expert 2GB
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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by dan glenn | last post: by
5 posts views Thread by RICHARD BROMBERG | last post: by
10 posts views Thread by David Garamond | last post: by
5 posts views Thread by toddles666 | last post: by
21 posts views Thread by Niu Xiao | last post: by
3 posts views Thread by R*a*h*u*L | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.