Not sure what might be wrong for you; the same code works for me.
$ cat> test.cc
#include <boost / date_time / gregorian / gregorian.hpp>
#include <boost / date_time / posix_time / posix_time.hpp>
using namespace boost :: posix_time;
int main () {
ptime now = second_clock :: universal_time ();
std :: cout << "Current Time is:" << to_iso_extended_string (now) << std :: endl;
ptime now_2 = microsec_clock :: universal_time ();
std :: cout << "Current Time is:" << to_iso_extended_string (now_2) << std :: endl;
return 0;
}
^ D
$ c ++ -lboost_date_time test.cc
$ ./a.out
Current Time is: 2009-10-14T16: 26: 55
Current Time is: 2009-10-14T16: 26: 55.586295
Implementation, second_clock uses time and microsec_clock uses gettimeofday or GetSystemTimeAsFileTime at the bottom, depending on the platform. Something is wrong with your platform - what is your OS and version?
What is your version of Boost? If it is 1.38 or lower, upgrade it to 1.39 or apply the hotfix to # 2809 manually.
--- boost / date_time / filetime_functions.hpp (revision 53621)
+++ boost / date_time / filetime_functions.hpp (revision 53622)
@@ -96.9 +96.7 @@
{
/ * shift is difference between 1970-Jan-01 & 1601-Jan-01
* in 100-nanosecond intervals * /
- const uint64_t c1 = 27111902UL;
- const uint64_t c2 = 3577643008UL; // issues warning without 'UL'
- const uint64_t shift = (c1 << 32) + c2;
+ const uint64_t shift = 116444736000000000ULL; // (27111902 << 32) + 3577643008
union {
FileTimeT as_file_time;
Windows FileTime has a different offset from UNIX time, and the code that was in Boost before will not generate the correct offset difference in some optimizing compilers.
ephemient
source share