Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Development
System Services
Time
Time Reference
Time Functions
 GetTickCount function
GetTickCount function

Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.

Syntax

DWORD WINAPI GetTickCount(void);

Parameters

This function has no parameters.

Return value

The return value is the number of milliseconds that have elapsed since the system was started.

Remarks

The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds. The resolution of the GetTickCount function is not affected by adjustments made by the GetSystemTimeAdjustment function.

The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. To avoid this problem, use the GetTickCount64 function. Otherwise, check for an overflow condition when comparing times.

If you need a higher resolution timer, use a multimedia timer or a high-resolution timer.

To obtain the time elapsed since the computer was started, retrieve the System Up Time counter in the performance data in the registry key HKEY_PERFORMANCE_DATA. The value returned is an 8-byte value. For more information, see Performance Counters.

To obtain the time the system has spent in the working state since it was started, use the QueryUnbiasedInterruptTime function.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Time Functions
Windows Time

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

Community Content   What is Community Content?
Add new content RSS  Annotations
not very precise      rogerdpack2   |   Edit   |   Show History
NB that even in windows 7 this has only precision of 0.015s $0Also another slightly more precise option is GetSystemTimeAsFileTime$0 $0which in windows 7 is microsecond precision, in windows XP is 0.015s precision.$0
Tags What's this?: Add a tag
Flag as ContentBug
Confusing statment about GetTickCount resolution adjustment      Noname_lc   |   Edit   |   Show History
This is a very confusing statement
"The resolution of the GetTickCount function is not affected by adjustments made by the GetSystemTimeAdjustment function."
The GetSystemTimeAdjustment does not adjust the time to counter for lag (either explicitly if provided by the programmer) or through synchronizing to some external source.
Also the Set/GetSystemTimeAdjustment does not change the resolution it only adjust for the drift.
Does the GetTickcount lags behind the systemtime (which is adjusted either every interval if SetSystemTimeAdjustment is enabled or by the system periodically which cause the jumps in the system time reported after the system adjusting the time with some external source)? If it does, does this mean the GetTickcount just adds the system time interrupt interval to this counter (on every clock interrupt). (e.g gettickcount is not adjusted for lag and will lag behind the system time delta taken from boot time)

Thanks.
Tags What's this?: Add a tag
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[DllImport("kernel32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern int GetTickCount();
Tags What's this?: Add a tag
Flag as ContentBug
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetTickCount() As Integer
End Function
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker