Boost date_time usage

Source: Internet
Author: User

1 posix_time

Boost: posix_time: ptime ptime1 = boost: posix_time: time_from_string (STD: string (str1 )));

Boost: posix_time: ptime ptime2 = boost: posix_time: time_from_string (STD: string (str2 )));

Determine equal functions

(Ptime1 = ptime2 )? True: false

Greaterthan Function

(Ptime1> ptime2 )? True: false

Lessthan Function

(Ptime1 <ptime2 )? True: false

When time1 = 00:00:00

Time2 = 2011-01-11

Test results:

Time1 and time2 are not equal

Time1 is not greater than time2

Time1 is smaller than time2

2 calculate the number of days of time difference

Date day1 = from_simple_string ("2001-10-9 ");
Date today = day_clock: local_day ();
Days days_limint = today-day1;
Struct stat stinfo;
Time_t tt;
Stat ("F: \ yuj \ test_env \ 11.txt", & stinfo );
Tt = stInfo. st_ctime;
Ptime pt = boost: posix_time: from_time_t (tt );
Date fileDate = pt. date ();
Days days_limint2 = fileDate-today;
Printf ("difference % d day \ n", days_limint.days ());
Printf ("difference % d day \ n", days_limint2.days ());

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.