Hi Alex,
Since your site will be deployed in US and is targetted for UK (GMT) users,
your case is relatively simple. But, its always better to develope for the
most general case (To and From any Time Zone so that your site does not break
when the location of your hosting provider is changed).
Unfortunately DateTime object gives us the luxury of only converting to and
from Universal Date Time (Formerly GMT) and Local Time (System Time Zone).
// expects DateTimeObject to contain Local Time and converts it to Universal
// Date Time value
DateTimeObject.ToUniversalTime()
// expects DateTimeObject to contain Universal Time and converts it to Local
// Date Time value
DateTimeObject.ToLocalTime()
So apparently there is no way to convert to and from a specific time zone.
But there are certain techinques to acheive what you need.
You can go along the following ways.
1) Use Javascript to pass the clients time zone offset to the server in a
hidden field and compute the British time on the server by first converting
the Server Local Time to Universal time and then adding the client's Time
Zone Offset to the Universal Time.
//javascript on client
dt = new Date();
locOffset = dt.getTimezoneOffset(); // get client's time zone offset
//Now pass this in a hidden feild to the server
//C# on Server
DateTime dt = DateTime.Now;
DateTime desiredTime = dt.ToUniversalTime().AddHours(offset);
//Note: offset is the client's time zone offset passed in the hidden field
2) If you want to perform all the computations on the server side then you
can probably use a class written by a gentleman which makes use of windows
APIs and can convert to any time zone.
http://staceyw.spaces.live.com/blog/cns!F4A38E96E598161E!931.entry
Regards,
Hameer Saleem
"Alex" wrote:
Hi
My website is hosted in the States (EST), but the website itself is
targeted for UK users (GMT).
How can I offset the time so that the server reports it as GMT when my
ASP.NET app needs to find out the current time?
..
Can I do this in web.config? If so how exactly?
Please note I am using ASP.NET 2.0 and VB.NET, and I can't set the
system clock of the server as it is owned by the web hosting provider.
Many thanks!
Alex