Hello, can someone point me in the direction of wxDateTime.
I have one that I save to disk as a string using wxDateTime::Format() via wxConfig. It is stored as mm/dd/yy hh:mm:ss (which is default I think). Now when the program starts back up I wish to put that value back into a wxDateTime variable via a wxConfig::Read() call.
Can someone explain how to accomplish this please? What I'm doing apparently isn't correct because my days/hours/minutes/seconds are all off.
Thanks
Need help with wxDateTime Topic is solved
Re: Need help with wxDateTime
Save the value of wxDateTime::GetTicks() into the config and use that value to recreate the wxDateTime object after loading.
Use the source, Luke!
Re: Need help with wxDateTime
Hi Doublemaxx, thanks for the reply. I think I need to elaborate more and show you the code in question.
Failed time is 02/05/18 15:22:04, current time is 02/05/18 15:53 and this is what is being logged:
[730485] - 00:31:19
[730485] - 00:31:20
[730485] - 00:31:21
[730485] - 00:31:22
I'm so close, I just cannot figure out the GetDays() issue. Can you save GetTicks with a predetermined string?
Thanks
Code: Select all
void networkMonitorFrame::processTimeSinceLastFailure(wxTimerEvent& WXUNUSED(event)) // Timer called once a second.
{
int resVal;
if((resVal = lastFailureIndicator->GetLabel().compare("N/A")) != 0) { // will be N/A until a failure.
wxDateTime currentTime = wxDateTime::Now();
wxDateTime timeSinceLastFailure = wxDateTime();
timeSinceLastFailure.ParseDateTime(lastFailureIndicator->GetLabel());
wxTimeSpan span = currentTime.Subtract(timeSinceLastFailure);
wxString str;
if(span.GetDays() > 0)
str.sprintf("[%02d] - %02d:%02d:%02llu", span.GetDays(), (span.GetHours() % 24), (span.GetMinutes() %60), (span.GetSeconds() %60));
else str.sprintf("%02d:%02d:%02d", (span.GetHours() % 24), (span.GetMinutes() %60), (span.GetSeconds() %60));
wxLogDebug(str); // Will eventually update another label
}
}
[730485] - 00:31:19
[730485] - 00:31:20
[730485] - 00:31:21
[730485] - 00:31:22
I'm so close, I just cannot figure out the GetDays() issue. Can you save GetTicks with a predetermined string?
Thanks
Re: Need help with wxDateTime
I think I figured it out, now I just need to figure out how to fix it.
wxDateTime::Now() returns a date with the year in 4 digits where as wxDateTime::Format() returns a date with the year in 2 digits. Thus is why get days is several hundred thousand days off.
wxDateTime::Now() returns a date with the year in 4 digits where as wxDateTime::Format() returns a date with the year in 2 digits. Thus is why get days is several hundred thousand days off.
Re: Need help with wxDateTime
No. wxDateTime::Now() just returns a wxDateTime object that at the current date/time. How it's formatted into a string is independent of the internal storage.wxDateTime::Now() returns a date with the year in 4 digits where as wxDateTime::Format() returns a date with the year in 2 digits.
In addition to lastFailureIndicator, i would store another wxDataTime object or just an integer with Ticks for the last error time. This will make everything much easier and more reliable.
Use the source, Luke!
Re: Need help with wxDateTime
Agreed, and I will probably do that, but isn't it cool to know that in the past 2000 years there has been 730485 days? Quick fix was to % the GetDays() with 730485 which returned the proper value. I'm re-writing the code now to use ticks instead of the way I was doing it.
Thanks
Thanks
Re: Need help with wxDateTime
FWIW, I store and load a datetime with wxConfig as a string using wxDateTime::FormatISOCombined() and wxDateTime::ParseISOCombined().