ex_month_add.xml 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "../../../tools/boostbook/dtd/boostbook.dtd">
  4. <!-- Copyright (c) 2001-2004 CrystalClear Software, Inc.
  5. Subject to the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <section id="date_time.examples.month_add">
  9. <title>Month Adding</title>
  10. <para>
  11. Adding a month to a day without the use of iterators.
  12. </para>
  13. <programlisting>
  14. <![CDATA[
  15. /* Simple program that uses the gregorian calendar to progress by exactly
  16. * one month, irregardless of how many days are in that month.
  17. *
  18. * This method can be used as an alternative to iterators
  19. */
  20. #include "boost/date_time/gregorian/gregorian.hpp"
  21. #include <iostream>
  22. int
  23. main()
  24. {
  25. using namespace boost::gregorian;
  26. date d = day_clock::local_day();
  27. add_month mf(1);
  28. date d2 = d + mf.get_offset(d);
  29. std::cout << "Today is: " << to_simple_string(d) << ".\n"
  30. << "One month from today will be: " << to_simple_string(d2)
  31. << std::endl;
  32. return 0;
  33. }
  34. ]]>
  35. </programlisting>
  36. </section>