My application receives a date/time field and a timezone code such as "EDT"
from a database. I need to convert the date/time to UTC using the timezone.
The timezone can be from anywhere on the globe.

TIA.

Re: How to convert any local time to UTC by Nick

Nick
Tue Oct 18 17:44:52 CDT 2005

You will want to use the DateTime structure which is part of the Base
Class libraries:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimememberstopic.asp


Re: How to convert any local time to UTC by RickPutnam

RickPutnam
Tue Oct 18 18:00:01 CDT 2005

Thanks, Nick.

I've actually gotten a little further than that. For example, there's a
ToUniversalTime method on the DateTime class which would do the trick if I
could tell it what time zone to use. Unfortunately, it just seems to assume
it is the local machine's time zone.

There is a TimeZone class, but I cannot figure out how to create an instance
based on a time zone other than the local machine's.

For instance, if I could write something like:

myDateTime.TimeZone = "CET"; //central european time
myDateTime = myDateTime.ToUniversalTime;

I'd be golden. But this is not how the stuff works apparently.

Based on the examples in MSDN and elsewhere, I can convert from my local
time to UTC and back to my heart's content, but converting Bangkok time to
UTC is not well covered.

Thanks for pitching in.

"Nick Hertl" wrote:

> You will want to use the DateTime structure which is part of the Base
> Class libraries:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimememberstopic.asp
>
>

RE: How to convert any local time to UTC by RickPutnam

RickPutnam
Wed Oct 19 08:32:04 CDT 2005

Not supported in the framework according to this FAQ article:

http://msdn.microsoft.com/netframework/programming/bcl/faq/DateAndTimeFAQ.aspx#Question6

What now?

"Rick Putnam" wrote:

> My application receives a date/time field and a timezone code such as "EDT"
> from a database. I need to convert the date/time to UTC using the timezone.
> The timezone can be from anywhere on the globe.
>
> TIA.

Re: How to convert any local time to UTC by David

David
Wed Oct 19 18:57:05 CDT 2005

Can you change the timezone of the local machine to the one you want, do the
conversion, and then change it back again? I have no idea what side effects
this would cause (probably a bunch) but it might be a workaround.


"Rick Putnam" <RickPutnam@discussions.microsoft.com> wrote in message
news:79813631-B990-48E2-9F12-04BCA5930E7C@microsoft.com...
> Not supported in the framework according to this FAQ article:
>
> http://msdn.microsoft.com/netframework/programming/bcl/faq/DateAndTimeFAQ.aspx#Question6
>
> What now?
>
> "Rick Putnam" wrote:
>
>> My application receives a date/time field and a timezone code such as
>> "EDT"
>> from a database. I need to convert the date/time to UTC using the
>> timezone.
>> The timezone can be from anywhere on the globe.
>>
>> TIA.



Re: How to convert any local time to UTC by William

William
Thu Oct 20 01:42:06 CDT 2005

Why couldn't you take the time as a local time, convert that to UTC and then
+- the given timezone (as int)?

--
William Stacey [MVP]

"David Levine" <noSpam12dlevineNNTP2@wi.rr.com> wrote in message
news:eLDKQjQ1FHA.3376@TK2MSFTNGP14.phx.gbl...
> Can you change the timezone of the local machine to the one you want, do
> the conversion, and then change it back again? I have no idea what side
> effects this would cause (probably a bunch) but it might be a workaround.
>
>
> "Rick Putnam" <RickPutnam@discussions.microsoft.com> wrote in message
> news:79813631-B990-48E2-9F12-04BCA5930E7C@microsoft.com...
>> Not supported in the framework according to this FAQ article:
>>
>> http://msdn.microsoft.com/netframework/programming/bcl/faq/DateAndTimeFAQ.aspx#Question6
>>
>> What now?
>>
>> "Rick Putnam" wrote:
>>
>>> My application receives a date/time field and a timezone code such as
>>> "EDT"
>>> from a database. I need to convert the date/time to UTC using the
>>> timezone.
>>> The timezone can be from anywhere on the globe.
>>>
>>> TIA.
>
>



Re: How to convert any local time to UTC by Marc

Marc
Thu Oct 20 07:55:03 CDT 2005

>Not supported in the framework according to this FAQ article:
>What now?

There's a pretty good article on time zones on CodeProject - also
includes some code to get access to ALL timezones defined in your
Windows PC, and it also supports doing stuff like convert times from
EDT to UTC (universal) and then on to your target time zone.

http://www.codeproject.com/dotnet/WorldClock.asp

Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch

Re: How to convert any local time to UTC by RickPutnam

RickPutnam
Thu Oct 20 19:22:05 CDT 2005

Thanks, Marc. That looks like a great solution. In the meantime, I've rolled
my own. But I'll look to use this in the next go round.

Thanks again.

"Marc Scheuner [MVP ADSI]" wrote:

> >Not supported in the framework according to this FAQ article:
> >What now?
>
> There's a pretty good article on time zones on CodeProject - also
> includes some code to get access to ALL timezones defined in your
> Windows PC, and it also supports doing stuff like convert times from
> EDT to UTC (universal) and then on to your target time zone.
>
> http://www.codeproject.com/dotnet/WorldClock.asp
>
> Marc
> ================================================================
> Marc Scheuner May The Source Be With You!
> Berne, Switzerland m.scheuner -at- inova.ch
>

Re: How to convert any local time to UTC by RickPutnam

RickPutnam
Thu Oct 20 19:23:03 CDT 2005

Thanks, David, but the app is going to run unattended on a production server.

Marc S, two responses down, points to a good solution at CodeProject if
you're interested.

"David Levine" wrote:

> Can you change the timezone of the local machine to the one you want, do the
> conversion, and then change it back again? I have no idea what side effects
> this would cause (probably a bunch) but it might be a workaround.
>
>
> "Rick Putnam" <RickPutnam@discussions.microsoft.com> wrote in message
> news:79813631-B990-48E2-9F12-04BCA5930E7C@microsoft.com...
> > Not supported in the framework according to this FAQ article:
> >
> > http://msdn.microsoft.com/netframework/programming/bcl/faq/DateAndTimeFAQ.aspx#Question6
> >
> > What now?
> >
> > "Rick Putnam" wrote:
> >
> >> My application receives a date/time field and a timezone code such as
> >> "EDT"
> >> from a database. I need to convert the date/time to UTC using the
> >> timezone.
> >> The timezone can be from anywhere on the globe.
> >>
> >> TIA.
>
>
>

Re: How to convert any local time to UTC by RickPutnam

RickPutnam
Thu Oct 20 19:26:04 CDT 2005

Yea, that's basically what I did. I was hoping there was an api I could use
rather than my own lookup for the offsets. Marc S, 1 response below, points
to a project at CodeProject that uses the registry.

Thanks.

"William Stacey [MVP]" wrote:

> Why couldn't you take the time as a local time, convert that to UTC and then
> +- the given timezone (as int)?
>
> --
> William Stacey [MVP]
>
> "David Levine" <noSpam12dlevineNNTP2@wi.rr.com> wrote in message
> news:eLDKQjQ1FHA.3376@TK2MSFTNGP14.phx.gbl...
> > Can you change the timezone of the local machine to the one you want, do
> > the conversion, and then change it back again? I have no idea what side
> > effects this would cause (probably a bunch) but it might be a workaround.
> >
> >
> > "Rick Putnam" <RickPutnam@discussions.microsoft.com> wrote in message
> > news:79813631-B990-48E2-9F12-04BCA5930E7C@microsoft.com...
> >> Not supported in the framework according to this FAQ article:
> >>
> >> http://msdn.microsoft.com/netframework/programming/bcl/faq/DateAndTimeFAQ.aspx#Question6
> >>
> >> What now?
> >>
> >> "Rick Putnam" wrote:
> >>
> >>> My application receives a date/time field and a timezone code such as
> >>> "EDT"
> >>> from a database. I need to convert the date/time to UTC using the
> >>> timezone.
> >>> The timezone can be from anywhere on the globe.
> >>>
> >>> TIA.
> >
> >
>
>
>