473,322 Members | 1,379 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,322 software developers and data experts.

DateTime & TimeZone

How do I convert Date to another TimeZone in C#? I am using .NET 1.1
right now.

Oct 3 '07 #1
2 2799
Benjamin The Donkey wrote:
How do I convert Date to another TimeZone in C#? I am using .NET 1.1
right now.
Other than doing it explicitly, I'm not aware of a good way. The only
conversion I know of is between UTC and local, according to your current
system settings.

If you know the specific UTC offset for the timezones, it should be a
simple matter to convert from one to the other.

I suppose you could modify the current system settings as part of the
conversion process, but that seems like a pretty ugly solution.

Pete
Oct 3 '07 #2
Benjamin The Donkey wrote:
How do I convert Date to another TimeZone in C#? I am using .NET 1.1
right now.
3 solutions:

1) wait for .NET 3.5

see
http://msdn2.microsoft.com/en-us/lib...rs(VS.90).aspx

2) sniff in registry

code snippet:

public static int GetUTCOffset1(string target)
{
RegistryKey tzs =
Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenS ubKey("Microsoft").OpenSubKey("Windows
NT").OpenSubKey("CurrentVersion").OpenSubKey("Ti me Zones");
foreach(string tzn in tzs.GetSubKeyNames())
{
if(tzn.Contains(target) ||
((string)tzs.OpenSubKey(tzn).GetValue("Display")). Contains(target))
{
return
-BitConverter.ToInt32((byte[])(tzs.OpenSubKey(tzn).GetValue("TZI")), 0);
}
}
throw new ArgumentException("Unknown timezone " + target);
}

3) use the Java support in vjslib

code snippet:

public static int GetUTCOffset2(string target)
{
java.util.TimeZone tz = java.util.TimeZone.getTimeZone(target);
return tz.getRawOffset() / 60000;
}

Arne

PS: There are a ton of additional problem in relation to summer time,
changes to/from summer time and historic dates, but the above should
get you started.
Oct 4 '07 #3

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

Similar topics

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...
9
by: rick cameron | last post by:
TimeZone - the only instance you can get is one representing the local time zone DateTime - cannot represent a time before 00:00:00 1 Jan 1 CE What were they thinking? This is a serious question...
1
by: Adam Monsen | last post by:
Say I have the following datetime object: >>> from datetime import datetime >>> d = datetime(2005, 8, 10, 15, 43) I happen to know this is a local time from the Netherlands, so I assume the...
1
by: James | last post by:
I need to import a bunch of data into our database for which there's a single entry each day which occurs at the same time every day in local time - so I need to convert this to UTC taking into...
0
by: David Pratt | last post by:
Hi. I am creating a couple of small methods to help me manage time from UTC as standard but I am getting strange results. If I start with a datetime of 2005-12-12 14:30:00 in timezone...
5
by: iulian.ilea | last post by:
Is correct to have a varchar field and insert dates of type dd/mm/yyyy into it? I choose this method because I have an application that runs on more than one server. So, if I used a datetime field...
9
by: Abhishek | last post by:
Hi I am trying to deserialize/ Parse a datetime object with the below string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time zone everything's fine however if i am in GMT + 5.30 i...
1
by: Matt | last post by:
Hi all, So a lot of digging on doing this and still not a fabulous solution: import time # this takes the last_modified_date naive datetime, converts it to a # UTC timetuple, converts that...
7
by: Looch | last post by:
All, I'm using a WinForm app that calls methods on a remotable object. The app server hosting the object is in New York. Using the same exact application, a Sql Server 2005 datetime column's...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.