Boost.deadline_timer time zone issues to be aware of when implementing timer functions

Source: Internet
Author: User

The use of Boost.deadline_timer () can be very convenient to implement the timer function, detailed reference: http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/reference/ Deadline_timer.html

For example, wait for the specified number of hours:

Boost::asio::io_service Ioservice;boost::asio::d eadline_timer TM (Ioservice, boost::p osix_time::seconds (5)); This specifies the absolute time, if the specified relative time is available time_duration the specified time period time.wait ();
You can also use the Deadline_timer two member function to specify the time to wait, deadline_timer.expires_at (specify absolute time), Deadline_timer.expires_from_now (Specify relative time) , in the waiting time can choose synchronous or asynchronous, time.wait () or time.async_wait (handler), the operation is more convenient, but also cross-platform.

But here's a question, like when I'm working on a timed upgrade tool, I want to specify the upgrade time for the Update tool, for example, 2015.4.12 00:00, according to the official website, (the absolute time is specified here)

Boost::asio::io_service ioservice;//Two different time formats Boost::asio::d Eadline_timer TM (Ioservice, boost::p osix_time::time_ From_string ("2015-04-12 23:01:50");//boost::asio::d Eadline_timer TM (Ioservice, boost::p osix_time::from_iso_string ("20150412t230150")); With T as delimiter time.wait ();
After doing so, you will find that the program does not wait for you to specify the time to start the corresponding task, but in advance for a long time, at that time to try a lot of methods or the best solution, and then carefully read the following document later found that the original boost time is UTC time, In the program should be replaced with local time, so you have to convert to the next time zone or use the local_time provided in Boost,


Boost::asio::io_service ioservice;boost::p osix_time::p time TM (boost::p osix_time::time_from_string ("2015-04-12 23:01:50 ")); TM-= boost::p osix_time::time_duration (8, 0, 0);   Beijing Time converted to UTC time, 8 hours difference Boost::asio::d eadline_timer timer (Ioservice, TM); timer.wait ();

Boost.deadline_timer time zone issues to be aware of when implementing timer functions

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.