Solved

Setting PC Time and Date using VB.net

Posted on 2014-04-01
1
1,231 Views
Last Modified: 2014-04-25
I am getting the time and date from a web service.  I would like to set the system date on my pc to this time and date.   Here is a sample code that I am using to figure it out.

Structure SYSTEMTIME
  Public Year As Short
  Public Month As Short
  Public DayOfWeek As Short
  Public Day As Short
  Public Hour As Short
  Public Minute As Short
  Public Second As Short
  Public Milliseconds As Short
End Structure

Declare Auto Function SetSystemTime Lib :Kernel32.dll" (byRef lpSystemTime as SYSTEMTIME) as UInt32


st.day = 1
st.month = 4
st.year = 2014
st.hour = 12
st.minute = 00

SetSystemTime(st)

When I read the time/date using the Now command it returns what I see on the pc.   When I set the time/date it sets the hour 4 hours behind.  

using the code above the time would be set for 8:00 am.

I changed my timezone to Azores and it works like I want it to.  Which is the Time I set is the Time I see on the clock.   How do I set it to display the time in my current time zone which is EST.

My second question is how do I set it for PM.  st.____  does not have an AM/PM setting.  I am currently adding 12 to the hour if I want to set it to PM.  This works, but is there a better way to do that.

Thank you for your help.
0
Comment
Question by:KennyMcAtee
1 Comment
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 250 total points
ID: 39970478
What is your time zone is it -4 hours as well?  The AM/PM is only as how it is being displayed and not used by time providers they use 'military' time 1300 hours for 1 PM.  Also the web service is probably using UTC time.. The ntp servers do use this.. you can set your computer to set itself using NTP servers  investigate the w32tm service
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now