473,406 Members | 2,710 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,406 software developers and data experts.

How to instantiate a particular TimeZone?

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(Date Time.Now)
but for the remote time zone?

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

Many thanks for your help...

Ciao
Michele
Jul 13 '07 #1
2 5154
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michele Locati" <ml*****@tiscali.itwrote in message
news:46**********************@reader4.news.tin.it. ..
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(Date Time.Now)
but for the remote time zone?

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

Many thanks for your help...

Ciao
Michele


Jul 13 '07 #2
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

Jul 13 '07 #3

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

Similar topics

0
by: Jason Kinkade | last post by:
I recently installed MySQL 4.0.18 on my slackware 9.1 machine (kernel 2.4.25) by compiling the source. It works fine, and all tests pass except one. The timezone test. Can someone tell me why...
7
by: Jim Davis | last post by:
I'm (still) working on an ISO 8601 date parser. I want to convert at least the formats described here: http://www.w3.org/TR/NOTE-datetime Well.. I've got most of it working (via RegEx's) good...
1
by: cnliou | last post by:
Hi! If I correctly understand v7.4 manual, value, say, '2003-11-26 12:00' in TIMESTAMP WITHOUT TIMEZONE column should output '2003-11-26 19:00' for "+08:00" timezone. The following test...
1
by: Raj Chudasama | last post by:
I have the following code for a clock in my gui. Everything works fine EXCEPT the following line when the TimeZone is changed in the windows. string tz = TimeZone.CurrentTimeZone.StandardName;...
6
by: Bijoy Naick | last post by:
I have an events table which stores the time of each event - the time and assoicated timezone. Is there a way of converting this time into GMT (with support for DST).. some sort of function which...
2
by: David Garamond | last post by:
When a timestamp string input contains a timezone abbreviation (CDT, PST, etc), which timezone offset is used? The input date's or today date's? The result on my computer suggests the latter. #...
13
by: Bruno Wolff III | last post by:
Recently there has been some discussion about attaching a timezone to a timestamp and some other discussion about including a 'day' part in the interval type. These two features impact each other,...
3
by: asanford | last post by:
I want to create a web service that allows the caller to pass a DateTime to the web service (that is, create a web method such as void MyWebMethod(DateTime dt).) However, I want to be able to...
2
by: =?Utf-8?B?Sm9ubnk=?= | last post by:
I have an ASP.NET 2.0 C# web application that is contacting an Exchange server using WEBDAV. It allows the users to look up appointments for a future date. The problem I have is determining the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.