Solved

Setting PC Time and Date using VB.net

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Authentication of Web Services 3 46
How do ASP.NET and MVC work together? 4 25
Connection String 16 43
Help with AsEnumerable(), LINQ 4 22
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

911 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

20 Experts available now in Live!

Get 1:1 Help Now