Windows time (VC++ 2010)

Feb 13, 2011 at 2:52pm
I am trying to find out how to get the date (day of week; day of month with 1st, 2nd, etc; month; and year). In Microsoft Visual C++ 2010 Express, the underlined section of the following code gets the error:
int tm::tm wday
Error: a nonstatic member reference must be relative to a specific oject
1
2
3
4
5
6
7
8
#include <iostream>
#include <time.h>
using namespace std;
int main () 
{
	int a;
	a = tm.tm_wday;
}

"a = tm::tm_wday;" gets the same error.
Please help me remove this error.
Feb 13, 2011 at 3:00pm
tm is a struct. You need to create an object to access it's member.
See http://www.cplusplus.com/reference/clibrary/ctime/localtime/ for an example
Feb 13, 2011 at 11:05pm
Look up GetSystemTime() and LPSYSTEMTIME struct.
Feb 15, 2011 at 4:40am
Use GetLocalTime(). It will give you local system time. If you want time in UTC format use GetSystemTime(). Both function using SYSTEMTIME struct.

Look at http://msdn.microsoft.com/en-us/library/ms724338%28VS.85%29.aspx
Topic archived. No new replies allowed.