Solved

GetSystemTime returns zero hours, minute, second and millisecond

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

760 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