Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the hour, minutes and seconds

const boost::posix_time::ptime now= boost::posix_time::second_clock::local_time();

year_ = now.date().year();
month_ = now.date().month();
day_ = now.date().day();

This is how I get the years, months and day out of boost::posix_time::ptime, but I can't figure out how to get the hour, minutes and seconds. Can you please help me out.

like image 635
Caesar Avatar asked Oct 05 '12 23:10

Caesar


People also ask

How do you calculate 1 hour in seconds?

How do I convert 1 hour in seconds? Multiply the hours by 60 to convert it to minutes, i.e., 1 hr × 60 = 60 minutes . Multiply the minutes by 60 to obtain the number of seconds, i.e., 60 minutes × 60 = 3600 seconds .

How do you calculate 1 hour in minutes?

There are 60 minutes in 1 hour. To convert from minutes to hours, divide the number of minutes by 60. For example, 120 minutes equals 2 hours because 120/60=2.

How do I calculate hours minutes and seconds in Excel?

Another simple technique to calculate the duration between two times in Excel is using the TEXT function: Calculate hours between two times: =TEXT(B2-A2, "h") Return hours and minutes between 2 times: =TEXT(B2-A2, "h:mm") Return hours, minutes and seconds between 2 times: =TEXT(B2-A2, "h:mm:ss")

How will you write 2.47 hours in hours minutes and seconds?

2.47 hours is 2 hours, 28 minutes and 12 seconds. 2.47 hours is also equivalent to 148 minutes and 12 seconds or 8892 seconds.


2 Answers

The answer is

now.time_of_day().hours(); 
now.time_of_day().minutes();
now.time_of_day().seconds();
like image 137
Caesar Avatar answered Nov 06 '22 22:11

Caesar


Hours_=now.time_duration().hours;
...
like image 1
Christian Stieber Avatar answered Nov 06 '22 23:11

Christian Stieber