Solved

Setting PC Time and Date using VB.net

Posted on 2014-04-01
1
1,286 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 80

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

820 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