How to instantiate a particular TimeZone?

M

Michele Locati

Hi to everybody

I'm working with dates and time, and I can't find the way to determine the
time in a generic TimeZone.

Here's an example of what I'd like to do:

// I get the local date and time
DataTime NowHere = DateTime.Now;

// I retrieve the UTC date and time
DateTime NowUtc = NowHere.ToUniversalTime();

// I instantiate a TimeZone object for a certain place on Earth
TimeZone ZoneThere = ??????

// I retrieve the date and time of that TimeZone
DateTime NowThere = ZoneThere.ToLocalTime(NowUtc);

....I really can't find what to write where I placed the question marks...

I could calculate manually the difference in hours, adding or substracting a
particolar TimeSpan.
In this case, anyway, I have the problem to know the daylight saving time
settings. For the local zone I can write something like;
DateTime.Now.IsDaylightSavingTime()
or
TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now)
but for the remote time zone?

....I don't know how to solve this problem...

Many thanks for your help...

Ciao
Michele
 
N

Nicholas Paldino [.NET/C# MVP]

Michele,

Unfortunately, you can't. This kind of functionality isn't going to be
available until .NET 3.5, with the TimeZoneInfo class. Right now, you can
only get time zone info for the time zone that the machine is currently
configured for.
 
S

salman

you can do this by import a function from kernel32.dll file.

public struct SYSTEMTIME
{
public ushort wDay;
public ushort wDayOfWeek;
public ushort wHour;
public ushort wMilliseconds;
public ushort wMinute;
public ushort wMonth;
public ushort wSecond;
public ushort wYear;
}


---[DllImport("kernel32.dll")]
---public static extern UInt16 SetSystemTime(ref SYSTEMTIME
lpSystemTime);


Salman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top