mirror of
https://github.com/boostorg/date_time.git
synced 2026-07-22 13:23:37 +00:00
Compare commits
2 Commits
issue-67
...
boost-1.30.0
| Author | SHA1 | Date | |
|---|---|---|---|
| e332516c1d | |||
| 858618e0da |
@@ -0,0 +1,18 @@
|
||||
// This example displays the amount of time until new year's in days
|
||||
|
||||
#include "boost/date_time/gregorian/gregorian.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
using namespace boost::gregorian;
|
||||
|
||||
date::ymd_type today = day_clock::local_day_ymd();
|
||||
date new_years_day(today.year + 1,1,1);
|
||||
date_duration dd = new_years_day - date(today);
|
||||
|
||||
std::cout << "Days till new year: " << dd.days() << std::endl;
|
||||
return 0;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
// Simple program that uses the gregorian calendar to find the last
|
||||
// day of the month.
|
||||
|
||||
#include "boost/date_time/gregorian/gregorian.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
std::cout << " Enter Year(ex: 2002): ";
|
||||
int year, month;
|
||||
std::cin >> year;
|
||||
std::cout << " Enter Month(1..12): ";
|
||||
std::cin >> month;
|
||||
try {
|
||||
int day = boost::gregorian::gregorian_calendar::end_of_month_day(year,month);
|
||||
boost::gregorian::date endOfMonth(year,month,day);
|
||||
std::cout << boost::gregorian::to_simple_string(endOfMonth) << std::endl;
|
||||
|
||||
//Iterate thru by months --
|
||||
boost::gregorian::month_iterator mitr(endOfMonth,1);
|
||||
boost::gregorian::date startOfNextYear(year+1,1,1);
|
||||
//loop thru the days and print each one
|
||||
while (mitr < startOfNextYear){
|
||||
std::cout << boost::gregorian::to_simple_string(*mitr) << std::endl;
|
||||
++mitr;
|
||||
}
|
||||
|
||||
}
|
||||
catch(...) {
|
||||
std::cout << "Invalid Date Entered" << std::endl;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
// Simple program that uses the gregorian calendar to find the last
|
||||
// day of the month.
|
||||
|
||||
#include "boost/date_time/gregorian/gregorian.hpp"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
using namespace boost::gregorian;
|
||||
typedef boost::date_time::month_functor<date> add_month;
|
||||
|
||||
date d = day_clock::local_day();
|
||||
add_month mf(1);
|
||||
date d2 = d + mf.get_offset(d);
|
||||
std::cout << to_simple_string(d2) << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user