I am resending this with proper subject line.

 

Thanks

 

From: Priyank Patel
Sent: Friday, October 22, 2010 8:47 AM
To: boost-users@lists.boost.org
Subject: Getting time from midnight in nanoseconds

 

Hi,

 

Can you please tell me if there is a way to get current time in nanoseconds using boost date_time library?

I have tried following but it doesn’t seems to be returning values in nanoseconds. I know I have used microsec_clock and that might be the problem but not sure what alternate to use.

Any help will be appreciated.

 

hrtime_t getCurrentTime() {

    boost::posix_time::ptime recvTime = boost::posix_time::microsec_clock::local_time();

    boost::posix_time::time_duration duration( recvTime.time_of_day() );

    return duration.total_nanoseconds(); // This call returns values in microseconds (last three digits are always zero in returned value)

}

 

Thanks

Priyank