473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 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 3216
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

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

Similar topics

4
by: dan glenn | last post by:
Say, I want to set a cookie and have it expire an hour after it's set. It's looking like this is only possible for browsers which are in the same time zone as my server?? In other words, if I...
5
by: RICHARD BROMBERG | last post by:
I am writing an ASP program that includes a Form. When the Form is submitted I use the Date() and Time() functions to put the date and time into the Body part of the e-mail. The time reported is...
2
by: CSN | last post by:
Is it possible to update the timezone part of timestamp fields in a single query? I have a bunch of values that are -06 I need changed to -07. BTW, better to use 'timestamp without time zone' or...
2
by: Mike Conmackie | last post by:
Greetings, Is there any way to force strftime() to ignore locale settings when formatting the resulting string? I have a requirement to create a specific date-time string format in UTC. ...
10
by: David Garamond | last post by:
The Postgres manual says: The AT TIME ZONE construct allows conversions of time stamps to different time zones. I'd guess most people would think what's meant here is something like "unit...
5
by: toddles666 | last post by:
Hi- Is there any way of restricting access to a database by application & account? For example, I only want the application APP1 to access the database using the USER1 account. I've tried to...
21
by: Niu Xiao | last post by:
I see a lot of use in function declarations, such as size_t fread(void* restrict ptr, size_t size, size_t nobj, FILE* restrict fp); but what does the keyword 'restrict' mean? there is no...
7
by: Dick | last post by:
I have a long list of events. I know where each event took place (globally) and when (using the event’s local time). I want to do some comparisons between these date/times. I thought I would...
1
by: Daz | last post by:
Hello everyone. I'm making a JavaScript clock which works in real time, and supports every time zone. I am struggling to find a way to see when the clocks are set back or forwards in a specific...
3
by: R*a*h*u*L | last post by:
Hi, Can anyone help me out . Req: I have to convert one of my server Date/Time (timezone) which is in America/Denver to UTC or GMT time zone . I have tried the below but both gives me same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.