Board index » cppbuilder » Date Time Conversions
Richard
![]() CBuilder Developer |
Date Time Conversions2007-10-27 03:43:49 AM cppbuilder25 It's me again. My Date Time Conversion keep coming out 1 hour off. I'm sure it has something to do with DST although I'm not using Daylight Saving Time. I set the system clock to GMT. //Calculates seconds from Now since Jan. 1, 2000 Midnight GMT double GetTimeStamp(void) { struct tm tm_now, tm_then; time_t now, then; double secs; int oyear, omonth, oday, ohour, omin, osec; //Time from Device char str[80]; //Get Date time from embedded device - Date Time 10/26/2007 03:01:30 GetDate(&oyear,&omonth,&oday); //Returns 2007,10,26 GetTime(&ohour,&omin,&osec); //returns 3,1,30 //Now Assign Embedded Devices GMT Time and Date to standard time rec tm_now.tm_sec = osec; tm_now.tm_min = omin; tm_now.tm_hour = ohour; tm_now.tm_year = oyear -1900; //2007 - 1900 = 107 tm_now.tm_mon = omonth -1; //10 - 1 = 9 tm_now.tm_mday = oday; tm_now.tm_isdst = 0; now = mktime(&tm_now); strcpy(str, asctime(&tm_now)); printf(ds,1,"Current Time is: %s \r\n",str); //This is correct !!! //Now Assign Date Time of 1/1/2000 00:00:00 to time rec tm_then.tm_sec = 0; tm_then.tm_min = 0; tm_then.tm_hour = 0; tm_then.tm_year = 2000 - 1900; tm_then.tm_mon = 0; tm_then.tm_mday = 1; tm_then.tm_isdst = 0; then = mktime(&tm_then); strcpy(str, asctime(&tm_then)); printf("Julian Start: %s \r\n",str); //This is correct secs = difftime(now,then); //Here I'm 3600 seconds off !! printf("Difference: %f \r\n",secs); return secs; } |