Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Time Zone and Setting System Time


Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2004, 09:05 AM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default Time Zone and Setting System Time


Hi All,

When we are using SetSystemTime API , how can we adjust the system time with respect to Time Zone?

For example,

I am living Eastern Time ( GMT - 5 ) , When I use the SetSystemTime API, windows calibrates the hour value ( expressed in UTC ) in SYSTEMTIME structure I pass and I get incorrect results.

Thanks all
Reply With Quote
  #2  
Old 11-20-2004, 10:59 AM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default

To make my question clearer...

What I am trying to figure out is :

I am in Eastern Time Time Zone (in the USA) which is -5GMT

To get 2PM, I set wHour to 19 (2 PM = 14hr UTC , 14 + 5 (my GMT) = 19 )

My problem is, since wHour accepts values between 0-23 , How can I set up the system time to for example 7PM ( 7 PM = 19hr UTC, 19 + 5 (my GMT) = 24 ). SYSTEMTIME structure naturally rejects the value 24 for wHour.
Code:
Private Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer ' Accepts values between 0 and 23 wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type
Reply With Quote
  #3  
Old 11-20-2004, 11:35 AM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,745
Default

Have you tried GetLocalTime? It performs the same function as GetSystemTime, only it will automatically use your time zone settings.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #4  
Old 11-20-2004, 11:49 AM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default

Thank you Mike, but I am having trouble for the setting part. What I mean is, I want to set the system time.

When I use SetSystemTime API and pass wHour=19 , Windows calibrates this value with respet to my Time Zone and that is where I am having trouble.

I am sure there is a proper solution, reading MSDN now but couldn't find the answer yet.

Thanks.
Reply With Quote
  #5  
Old 11-20-2004, 11:56 AM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,745
Default

Can't believe I missed that one...

Well, you're going to have to do some date math.
Code:
Add 5 to wHour.

'Now, we're going to use the Mod function
If NewHour >= 24 Then
    wHour = NewHour Mod 24
    wDay = wDay + 1
End If

'However, what if it's the end of the month?
If wDay is endofmonth Then
   Increment month
End If
'You're gonna have to check for endofmonth, as it changes per month (you can use the value for wMonth for this)

'What if it's the end of the year?  (you'll need to check for leap years too)
If wDay = endofyear Then
    wYear = wYear + 1
End If
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #6  
Old 11-20-2004, 12:10 PM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default

I hate myself!!

Thank you Mike, I dont beleive I spent last two hours thinking about it.

I see that your title is "Brain damaged Coder" BUT at least yours is still working

Cheers!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->