Solved

Setting PC Time and Date using VB.net

Posted on 2014-04-01
1
1,302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 81

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article will show, step by step, how to integrate R code into a R Sweave document
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

738 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