Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

more precise second of time in VC++

I am using _strtime to get the current time, but the second is only integer. What should I use to get the second with more precision like 1/100 seconds? The following is what I am doing:

char today_char[30], *char_buff;

_strtime( today_char );
char_buff = strtok(today_char, ":");hour = atoi(char_buff);
char_buff = strtok(NULL, ":");minute = atoi(char_buff);
char_buff = strtok(NULL, ":");second = atoi(char_buff);

Thanks in advance.

ScatJay
0 Kudos
Message 1 of 4
(4,793 Views)
You could try GetLocalTime or GetSystemTime instead. The SYSTEMTIME structure that's returned from these functions has a wMilliseconds member that specifies the millisecond portion of the time. For example:


SYSTEMTIME t;
::GetLocalTime(&t);

std::cout << t.wHour << ":" << t.wMinute << ":" << t.wSecond << "." << t.wMilliseconds << std::endl;


- Elton
Message 2 of 4
(4,785 Views)
Elton, thanks for the excellent answer. I did make it work with GetLocalTime, but when I tried the following with GetSystemTime, I got the following error:

SYSTEMTIME st;
GetLocalTime(&st); // This is fine.
GetSystemTime(&st); // This returns the following error:

error C2660: 'CVI_GetSystemTime' : function does not take 1 parameters

Do I need to update my NI Mesaurement Studio? Thanks again for your time.

-ScatJay
0 Kudos
Message 3 of 4
(4,779 Views)
The problem is that CVI defines its own GetSystemTime function, which looks like this:

int GetSystemTime (int *hours, int *minutes, int *seconds);


There's a warning in the CVI help for GetSystemTime that states:


Windows SDK also contains a GetSystemTime function. If you include windows.h and do not include utility.h, you will receive compile errors if you call the GetSystemTime function.


For information on how to workaround this issue, see the Knowledge Base article "How Do I Call a Windows SDK Function That has the Same Name as a CVI function?". The second example even uses GetSystemTime as an example.

- Elton
0 Kudos
Message 4 of 4
(4,772 Views)