[C++ timestamp] How to get correct timestamp

Hello, i need to make function where i get timestamp from date, i have function to get actual timestamp, it works and i make duplicate of this one and here i want parse ints with day, month, etc and return timestamp of this date. why i still getting -1 on output. Thanks :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static long CasToTimestamp(int den, int mesiac, int rok, int hodina, int minuta, int sekunda)
{
	//time_t t = time(NULL);
	//struct tm * now = localtime(&t);

	struct tm t1;
	time_t t_of_day;

	t1.tm_year = rok;
	t1.tm_mon = mesiac - 1;
	t1.tm_mday = den;
	t1.tm_hour = hodina;
	t1.tm_min = minuta;
	t1.tm_sec = sekunda;
	t1.tm_isdst = -1;

	t_of_day = mktime(&t1);
	return t_of_day;
}
this one works

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static long CasToTimestamp(int den, int mesiac, int rok, int hodina, int minuta, int sekunda)
{
	//time_t t = time(NULL);
	//struct tm * now = localtime(&t);

	time_t rawtime;
	struct tm * timeinfo;
	time(&rawtime);
	timeinfo = localtime(&rawtime);

	timeinfo->tm_year = rok - 1900;
	timeinfo->tm_mon = mesiac - 1;
	timeinfo->tm_mday = den;
	timeinfo->tm_hour = hodina;
	timeinfo->tm_min = minuta;
	timeinfo->tm_sec = sekunda;

	return mktime(timeinfo);
}
Topic archived. No new replies allowed.