473,395 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Offsetting timezones

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

Dec 3 '06 #1
5 7791
In your case it is relatively simple. Since UK is GMT, just convert the
localtime that the US server provides you into GMT using the
DateTime.ToUniversalTime( ) function.

For the more general case (ie. user is located anywhere in the world) you
will have to perform your own DateTime biasing to compute the local time for
the user's location. You will also need your own mechanism to know what
location the user is in. Generally this would also be associated with other
Culture-related behaviour as well (eg. how numbers are formatted, how dates
are formatted etc), so it's really just an extension of that.

..NET has a TimeZone class, which I [at first] mistakenly thought it might
behave somewhat like Cultures (ie. get a TimeZone class for a particular
timezone). But it doesn't do that, so it doesn't seem particularly useful.
"Alex" <po******@alexshirley.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
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

Dec 3 '06 #2
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

Dec 4 '06 #3
Thanks for the quick response guys! Useful.

The ASP.NET app I'm using is actually DotNetNuke 4.3.7, I logged a post
here about it here:
(http://www.dotnetnuke.com/Community/...s/Default.aspx)

The app appears to support timezones as far as individual users and
website portals (if different portal were based in different
countries), but appears to fall down hill when the server is based in a
different timezone, like in my scenario (I'm not the only DNN user with
this problem it seems).

I was trying to find a way of conning the whole app into accepting a
GMT time, maybe overriding the datetime class or something. Then
everything would work beautifully (although the SQL server backend for
datestamps would be the next problem).

It's a pity ASP.NET doesn't have a setting in web.config that would
adjust the app timezone, wouldn't you think this would be a sensible
feature?

Cheers!

Alex

Dec 4 '06 #4
re:
It's a pity ASP.NET doesn't have a setting in web.config that would
adjust the app timezone, wouldn't you think this would be a sensible
feature?
Hi, Alex.

If you download the source for Community Server
( http://communityserver.org/files/default.aspx )
you'll see a helper class named GeographicTimeZone.cs

That class, along with TimezoneDropDownList.cs and timezones.xml
allows users to adjust their timezone setting.

It shouldn't be too difficult to adapt that code for your purposes.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Alex" <po******@alexshirley.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
Thanks for the quick response guys! Useful.

The ASP.NET app I'm using is actually DotNetNuke 4.3.7, I logged a post
here about it here:
(http://www.dotnetnuke.com/Community/...s/Default.aspx)

The app appears to support timezones as far as individual users and
website portals (if different portal were based in different
countries), but appears to fall down hill when the server is based in a
different timezone, like in my scenario (I'm not the only DNN user with
this problem it seems).

I was trying to find a way of conning the whole app into accepting a
GMT time, maybe overriding the datetime class or something. Then
everything would work beautifully (although the SQL server backend for
datestamps would be the next problem).

It's a pity ASP.NET doesn't have a setting in web.config that would
adjust the app timezone, wouldn't you think this would be a sensible
feature?

Cheers!

Alex

Dec 4 '06 #5
Thanks Juan!

Alex
Juan T. Llibre wrote:
re:
It's a pity ASP.NET doesn't have a setting in web.config that would
adjust the app timezone, wouldn't you think this would be a sensible
feature?

Hi, Alex.

If you download the source for Community Server
( http://communityserver.org/files/default.aspx )
you'll see a helper class named GeographicTimeZone.cs

That class, along with TimezoneDropDownList.cs and timezones.xml
allows users to adjust their timezone setting.

It shouldn't be too difficult to adapt that code for your purposes.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Alex" <po******@alexshirley.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
Thanks for the quick response guys! Useful.

The ASP.NET app I'm using is actually DotNetNuke 4.3.7, I logged a post
here about it here:
(http://www.dotnetnuke.com/Community/...s/Default.aspx)

The app appears to support timezones as far as individual users and
website portals (if different portal were based in different
countries), but appears to fall down hill when the server is based in a
different timezone, like in my scenario (I'm not the only DNN user with
this problem it seems).

I was trying to find a way of conning the whole app into accepting a
GMT time, maybe overriding the datetime class or something. Then
everything would work beautifully (although the SQL server backend for
datestamps would be the next problem).

It's a pity ASP.NET doesn't have a setting in web.config that would
adjust the app timezone, wouldn't you think this would be a sensible
feature?

Cheers!

Alex
Jan 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: B. G. Mahesh | last post by:
hi I am using PHP 4.x and MySQL. The database has the list of countries, cities and timezones. I would like to convert the time from one zone to another zone . It is not that difficult to...
0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
13
by: Michael | last post by:
I would like to set the timezone of a thread to allow me to calculate the UTC time for data sourced from a number of time zones. Although this can be done in C and C++, I annot find how to do...
0
by: Robert Treat | last post by:
I am trying to figure out if there is a way to determine the timezones supported in postgresql from within the database. If you look at...
1
by: Flack | last post by:
Hey guys, I need to compare two times that the user selects. The user selects the hour, date, and timezone (which can be either NY, LN, or HK timezones). How can I compare two dates of...
7
by: =?Utf-8?B?U3R1?= | last post by:
I have a ASP.NET Ajax app (using client library) calling ASP.NET Ajax-enabled web services. We are making use of the javascript proxies generated by ASP.NET Ajax. The problem we have is that the...
3
by: Daz | last post by:
Hello everyone. I am creating a JavaScript project which will allow users to see what time it is in other countries. I am wondering if there's any way to have the server work this out, without...
7
by: David T. Ashley | last post by:
In a web database (PHP), per user, I'd like to allow each user to specify their timezone (this would change how times are adjusted for display for that user). How do I enumerate all possible...
27
by: Sanjay | last post by:
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.