Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

convert to a time and compaire to see if more than a minute difference found?

37 views
Skip to first unread message

SpreadTooThin

unread,
Apr 4, 2015, 5:03:25 PM4/4/15
to
I'm parsing a few million lines of log files and trying to sort things out.

My log files begin with stuff like:

2015-03-23 11:56:03,752

where 752, is milliseconds.

I have two log lines and I want to know (in milliseconds) what delta t is.

What std c++ object should I use and how do I get delta-t?

Ian Collins

unread,
Apr 4, 2015, 5:59:20 PM4/4/15
to
Probably the most pragmatic approach is to read the timestamp, split the
result int milliseconds and the rest and then use your platform's native
date conversion functions or std::get_time to get a time in seconds.

--
Ian Collins
Message has been deleted

SpreadTooThin

unread,
Apr 4, 2015, 7:02:36 PM4/4/15
to
class logTime {

public:
void setTime(string s)
{
sscanf(s.c_str(), "%04d-%02d-%02d %02d:%02d:%02d,%d", &year, &month, &day, &hour, &minute, &second, &millisecond);
cout << "logTime" << year << "-" << month << "-" << day << " " << hour << ":" << minute << ":" << second << "," << millisecond << std::endl;
}
double deltaTinMS(logTime lt2)
{
time_t t2 = lt2.t1;
double deltaT;
deltaT = difftime(t2, t1);
deltaT = (deltaT * 1000) + lt2.millisecond - millisecond;
return deltaT;
}

private:
int year;
int month;
int day;
int hour;
int minute;
int second;
int millisecond;
std::time_t t1;
};

Ian Collins

unread,
Apr 4, 2015, 8:24:35 PM4/4/15
to
How is that better than the suggestions offered?

How do you calculate time differences?

--
Ian Collins

Scott Lurndal

unread,
Apr 6, 2015, 9:41:03 AM4/6/15
to
SpreadTooThin <bjobr...@gmail.com> writes:
>I'm parsing a few million lines of log files and trying to sort things out.
>
>My log files begin with stuff like:
>
>2015-03-23 11:56:03,752

On a posix platform, use 'strptime'.

Martijn Lievaart

unread,
Apr 8, 2015, 10:21:06 AM4/8/15
to
Sorry for maybe stating the obvious, and at the chance of insulting
people, why use C++ for this? Perl seems like an obvious choice, but
there are many more text parsing oriented languages that seem better
suited than C++.

M4
0 new messages