Converting SYSTEMTIME to time_t?

I am having trouble converting SYSTEMTIME to time_t

Can anyone help me with this situation please?
Not sure if there is another way but you could probably use std::mktime.
http://en.cppreference.com/w/cpp/chrono/c/mktime
bump -
bump --
I meant something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <ctime>

int main()
{
	SYSTEMTIME st;
	std::tm tm;
	
	tm.tm_sec = st.wSecond;
	tm.tm_min = st.wMinute;
	tm.tm_hour = st.wHour;
	tm.tm_mday = st.wDay;
	tm.tm_mon = st.wMonth - 1;
	tm.tm_year = st.wYear - 1900;
	tm.tm_isdst = -1;
	
	std::time_t t = std::mktime(&tm);
}
Thanks for your reply, mktime returns -1 with that code
Did you use a valid SYSTEMTIME?
yeah its from the calendar component
Sorry mate it was the wrong SYSTEMTIME after that. I think I been working too long lol break for me. It works brilliantly thanks mate. Could you explain to me why you have to minus 1900 and 1 from the month?
It's just that they store some of the data differently. SYSTEMTIME stores the month as a number from 1 to 12 while std::tm stores it as a number from 0 to 11. SYSTEMTIME stores the year like you would expect (starting from 0) but std::tm stores it as the number of years since 1900.

You can compare them for yourself if you want:
http://en.cppreference.com/w/cpp/chrono/c/tm
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724950.aspx
thanks
Topic archived. No new replies allowed.