Solved

GetSystemTime returns zero hours, minute, second and millisecond

Posted on 2013-12-04
4
358 Views
Last Modified: 2013-12-09
Hi!

Trying to get the system time using the Windows API GetSystemTime. It runs but returns zero for hour, minute, second and millisecond.

Using VB.NET in Visual Studio 2010 on a Windows 7 x86 machine.

Code below:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Public Class clsSocket

    Private Declare Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)

     Private Structure SYSTEMTIME
        Public wYear As Integer
        Public wMonth As Integer
        Public wDayOfWeek As Integer
        Public wDay As Integer
        Public wHour As Integer
        Public wMinute As Integer
        Public wSecond As Integer
        Public wMilliseconds As Integer
    End Structure

    Public Sub CheckTime()

        Dim StartTime As SYSTEMTIME
        Dim EndTime As SYSTEMTIME

        GetSystemTime(StartTime)

   System.Diagnostics.Debug.WriteLine("Start: " & StartTime.wSecond & "." & StartTime.wMilliseconds & " End: " & EndTime.wSecond & "." & EndTime.wMilliseconds)
   
End Sub
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Any ideas?

Thanks in advance!

/Lospilotos
0
Comment
Question by:lospilotos
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 39697414
Why wouldn't you just use DateTime.Now?
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 250 total points
ID: 39697436
kaufmed is correct.

if you need time details DateTime.Now.ToString("HH:mm:ss"))
in msdn you will get more details
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
0
 

Assisted Solution

by:lospilotos
lospilotos earned 0 total points
ID: 39697463
Thanks, how silly of me: ToString("HH:mm:ss.fff") did the trick.
0
 

Author Closing Comment

by:lospilotos
ID: 39705733
ToString("HH:mm:ss.fff") did the trick.
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

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

867 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

16 Experts available now in Live!

Get 1:1 Help Now