Simple use of the boost library-processing of time and date (1)

Source: Internet
Author: User

Processing of time and date is always a complicated problem, while processing of time and date in C ++ is also relatively simple, unlike Java and C #, the stream provides a class that is very convenient and easy to use. However, with the launch of boost, time processing has become more and more simple and convenient. Today we will learn some convenient processing methods:

First, let's take a look at a basic class for time processing in boost, which is also the base class of several subsequent classes-timer. timer class can measure the passage of time. Based on different platforms, it provides time control in milliseconds or even microseconds. We can also use it to make a very simple timer. below, we use code to explain the usage of Timer:

#include <iostream>#include <boost/timer.hpp>int main() {    boost::timer t;    std::cout << "Max timespan : " << t.elapsed_max() / 3600 << "h" << std::endl;    std::cout << "Min timespan : " << t.elapsed_min() << "s" << std::endl;    std::cout << "Time elapsed : " << t.elapsed() << std::endl;    return 0;}

Generally, we only need to use the above three Timer class member methods. The function names also probably know their usefulness. They are: getting the maximum measurable time span, the Unit is hours. The minimum time span that can be measured is measured in seconds. It should be noted that the starting time of the elapsed time is when the timer instance is constructed, not when the program starts to run!

Timer class is more than enough for short-term processing, because its maximum time span is several hundred hours, that is, we should use it to test the running time of some algorithms. If the processing time is in the unit of day, month, and year, you cannot continue to use the Timer class. Let's talk about the specific usage!

Simple use of the boost library-processing of time and date (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.