Solved

GetSystemTime returns zero hours, minute, second and millisecond

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user 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…

837 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