|
Boost Users : |
From: Barry Andrews (titanandrews_at_[hidden])
Date: 2006-12-23 15:41:11
Hi Boost Users,
I am attempting to use the boost library date_time to create a platform
independent function to get the system time in milliseconds. Basically, I
need a millisecond precision timing mechanism. I read over the docs and
looked at the examples from this library and came up with something that I
thought would work, but it doesn't. :(
ptime time_t_epoch(date(1970,1,1));
time_zone_ptr zone(new posix_time_zone("MST-07"));
local_date_time dt_epoch(time_t_epoch, zone);
time_zone_ptr zone2(new posix_time_zone("MST-07"));
local_date_time ldt = local_microsec_clock::local_time(zone2);
time_duration diff = ldt.utc_time() - dt_epoch.utc_time();
long milli = diff.total_milliseconds();
cout << milli << endl;
What I get is a negative number.
The function I want should have the exact same behavior as
java.lang.System.currentTimeMillis() which returns "the difference, measured
in milliseconds, between the current time and midnight, January 1, 1970 UTC."
Is there a way to achieve this with boost? Is so, can someone please give me
some hints as to how I can do this?
many thanks for your help!
-B
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net