Solved

GetSystemTime returns zero hours, minute, second and millisecond

Posted on 2013-12-04
4
362 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

770 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