datetime conversions - US CST

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hey everybody.

Is there an easy way in vb.net to convert the local time of a machine
to US CST ? My machines are distributed throughout and the server is
requesting we send the time of the txns in US CST.

TIA,
Mark
 
Mark,
Unfortunately System.DateTime (VB's Date) only knows how to convert a
Universal Time to Local Time & convert Local Time to UniversalTime.

I would recommend that each of your machines convert local time to universal
time, then send that time to the server. The server can then convert the
universal time to local time which will be CST.

You can use
- DateTime.Now - to get current local date & time
- DateTime.UtcNow - to get current date & time in universal time (UTC)
- DateTime.ToUniversalTime - to convert local time to universal time
- DateTime.ToLocalTime - to convert universal time to local time


Hope this helps
Jay
 
Thanks Jay.

Unfortunately, in this environment, the server that I referred to is
not the end location and is not in CST. For this particular txn, its
just passing thru the message on to the final dest. So the server
would have the same problem. I haven't looked yet, but does the
localtime include the timezone locally also, so I would have that
information ?
 
Mark,
In case you missed my point. I am suggesting you only send time in universal
time between servers. I would convert local time to universal time on the
originating systems only (not pass thru systems).

No matter what server you are on, or how many you pass thru, the time will
still be universal time. Hence there is no worry as to what the local time
is!


To answer your question, DateTime does not itself keep track as to whether
it is in Local or Universal time you need to do this yourself. I normally do
this via the context of the variable.

You can use System.TimeZone.CurrentTimeZone to find out what the current
time zone on your system is.

Hope this helps
Jay


Mark said:
Thanks Jay.

Unfortunately, in this environment, the server that I referred to is
not the end location and is not in CST. For this particular txn, its
just passing thru the message on to the final dest. So the server
would have the same problem. I haven't looked yet, but does the
localtime include the timezone locally also, so I would have that
information ?

"Jay B. Harlow [MVP - Outlook]" <[email protected]> wrote in message
Mark,
Unfortunately System.DateTime (VB's Date) only knows how to convert a
Universal Time to Local Time & convert Local Time to UniversalTime.

I would recommend that each of your machines convert local time to universal
time, then send that time to the server. The server can then convert the
universal time to local time which will be CST.

You can use
- DateTime.Now - to get current local date & time
- DateTime.UtcNow - to get current date & time in universal time (UTC)
- DateTime.ToUniversalTime - to convert local time to universal time
- DateTime.ToLocalTime - to convert universal time to local time


Hope this helps
Jay
 

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

Back
Top