472,780 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 472,780 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);
  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.

Bharath Reddy VasiReddy
Apr 6 '10 #1
2 3136
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

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...
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...
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...
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. ...
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...
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...
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...
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...
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...
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...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
How does React native implement an English player?

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.