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
- 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.
Expand|Select|Wrap|Line Numbers
- 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