Struct tm

	struct tm Tm1 = {0};	//<<The = {0} is really important to ensure the struct if properly initialised, you can sometimes get weird runtime issues if you don't do this

	Tm1.tm_year = (2015 - 1900);	//years since 1900 (we must be >= 1970 for time_t based calcs)
	Tm1.tm_mon = 1;		//months since January (0-11)
	Tm1.tm_mday = 18;
	Tm1.tm_hour = 12;
	Tm1.tm_min = 03;
	Tm1.tm_sec = 48;

Note:
tm_year is years since 1900!!
tm_month is months since January (0-11)!!
Note when converting to time_t your year must be >= 1970 as time_t is usually based from 00:00, Jan 1 1970 UTC!

Copy struct tm

You can just use a normal equals:

	struct tm Tm1 = {0};
	struct tm Tm2 = {0};

	//...

	Tm2 = Tm1;
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *