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.
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.
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
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
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); }
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
Comment