Solved

Setting PC Time and Date using VB.net

Posted on 2014-04-01
1
1,269 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 79

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
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.

821 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