Re: convert to a time and compaire to see if more than a minute difference found?
SpreadTooThin <bjobrien62@gmail.com> writes:
2015-03-23 11:56:03,752
I have two log lines and I want to know (in milliseconds) what delta t is.
You could use the I/O manipulator get_time from iomanip, but
it does not seem to support milliseconds. So, you still have
to parse the milliseconds manually. Then calculate the time
difference of the two "struct tm" using mktime and difftime
and then manually adjust for the two millisecond values.
Manually parsing a time looks like this:
#include <sstream>
#include <ctime>
....
::std::stringstream source{ "2015-03-23 11:56:03,752" };
int year; source >> year; source.get();
int month; source >> month; source.get();
int day; source >> day; source.get();
....
::std::tm tm0;
tm0->tm_year = year - 1900;
....
For Java, I wrote my one date-time library
?de.dclj.ram.system.gregorian? that already can parse split
seconds. I now report about this Java library:
Say, we would like to get the difference in seconds between
1784-02-14T02:29:21.574572+01:00 and
2108-08-16T05:49:31.346257+02:00 using a proleptic
astronomical calendar that does not take leap seconds into regard:
public class Main
{
public static void main( final java.lang.String[] args )
throws java.text.ParseException
{
final de.dclj.ram.system.gregorian.Instant instant =
new de.dclj.ram.notation.iso8601.Instant
( "1784-02-14T02:29:21.574572+01:00" ).getGregorian();
final de.dclj.ram.system.gregorian.Instant instant1 =
new de.dclj.ram.notation.iso8601.Instant
( "2108-08-16T05:49:31.346257+02:00" ).getGregorian();
java.lang.System.out.println
( instant1.bigFloatValue().minus( instant.bigFloatValue() )); }}
/* The output is:
10240309209.771685
*/