[Boost] Date Constructor

Source: Internet
Author: User

1. Overview
Header file: <boost/date_time.hpp>
This database uses the calendar date system and supports from 1400-Jan-01 to 9999-dec-31.
Class boost: Gregorian: date is the main time type used by the user.
2. Constructor
In date_time, special_values is used to define some special time concepts, including:
Pos_infin (positive infinity)
Neg_infin (negative infinity)
Not_a_date_time (invalid time)
Min_date_time (minimum date or time)
Max_date_time (maximum date or time)
Five is_xxx functions are provided to check whether the date is a special date,
Is_infinity (whether it is an infinite date)
Is_neg_infinity (whether it is a negative infinite date)
Is_pos_infinity (whether it is a positive and infinite date)
Is_not_adate (whether it is an invalid date)
Is_special (whether it is any special date)
3. Example

Void test_dt_construct () {using namespace boost: Gregorian; // 1. common constructor types include date D0; Date D1 (2008, 8, 9); // The most common constructor date D2 (D1 ); // copy and construct date ds1 (neg_infin); Date DS2 (pos_infin); Date DS3 (not_a_date_time); Date DS4 (max_date_time); // 9999-dec-31date ds5 (min_date_time ); // 1400-jan-01assert (d0.is _ not_a_date (); Assert (d0.is _ special (); Assert (ds1.is _ special (); Assert (ds2.is _ special ()); assert (ds3.is _ special () ); Assert (! Ds4.is _ special (); Assert (! Ds5.is _ special (); // 2. use a string to construct date dstr1 (from_string ("2011/08/09"); Date dstr2 (from_string ("2011-08-09"); Date dstr3 (from_string ("2011-feb-28 ")); date dstr4 (from_string ("2011-February-28"); Date dstr5 (from_undelimited_string ("20110809 ")); // The uncommon string date dstr6 (from_us_string ("Feb-28-2011"); // The complete month word can also date dstr7 (from_uk_string ("28-feb-2011 ")); // The complete month word can also be // 3. use clock to construct date DC1 (day_clock: local_day (); Date DC2 (day_clock: universal_day (); // 4. exception during construction try {// year, month, and day will throw an exception when the range is exceeded. date D6 (1300, 12, 25);} catch (STD: exception & E) {STD: cout <E. what () <STD: Endl ;}}

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.