COleDateTimeSpan wierdness....
-
Can anyone tell me why the following code does what it does: (Note that the code has been trivialised for readability :)) ZeroTime.SetDateTime( 1970, 1, 1, 0, 0, 0 ); OtherTime.SetDateTime(1970, 1, 1, 0, 0, 10); COleDateTimeSpan TimeDifference; TimeDifference= (OtherTime - ZeroTime); CString Seconds, TotalSeconds; Seconds.Format("%10d", TimeDifference.GetSeconds()); TotalSeconds.Format("%10d", TimeDifference.GetTotalSeconds()); Seconds.Replace(' ','0'); Seconds.Replace(' ','0'); After all that I get the following output: Seconds = 0000000010 TotalSeconds = 0000000000 Why can't GetTotalSeconds determine the correct number of seconds?? Environment is Visual C++ 6, SP5 on Win NT4 SP6 It's driving me nuts!! Thanks anyone that can help! :-O Senior Test Engineer GLI Australia www.gli.com.au
-
Can anyone tell me why the following code does what it does: (Note that the code has been trivialised for readability :)) ZeroTime.SetDateTime( 1970, 1, 1, 0, 0, 0 ); OtherTime.SetDateTime(1970, 1, 1, 0, 0, 10); COleDateTimeSpan TimeDifference; TimeDifference= (OtherTime - ZeroTime); CString Seconds, TotalSeconds; Seconds.Format("%10d", TimeDifference.GetSeconds()); TotalSeconds.Format("%10d", TimeDifference.GetTotalSeconds()); Seconds.Replace(' ','0'); Seconds.Replace(' ','0'); After all that I get the following output: Seconds = 0000000010 TotalSeconds = 0000000000 Why can't GetTotalSeconds determine the correct number of seconds?? Environment is Visual C++ 6, SP5 on Win NT4 SP6 It's driving me nuts!! Thanks anyone that can help! :-O Senior Test Engineer GLI Australia www.gli.com.au
The problem is that you are trying to format the return value of GetTotalSeconds function as if it were an integer. According to MSDN the function is prototyped as a double even though it returns an integer. Try this: TotalSeconds.Format("%10d", **(int)**TimeDifference.GetTotalSeconds()); This works for me.
-
The problem is that you are trying to format the return value of GetTotalSeconds function as if it were an integer. According to MSDN the function is prototyped as a double even though it returns an integer. Try this: TotalSeconds.Format("%10d", **(int)**TimeDifference.GetTotalSeconds()); This works for me.
Yes, thanks for the info, I ended up doing this: long Difference = (long)TimeDifference.GetTotalSeconds(); TotalSeconds.Format(("%10d", Difference); (or something similar anyway). No need to tear my hair out anymore! Thanks for the info! Regards Senior Test Engineer GLI Australia www.gli.com.au