#include#include using namespace std; int main() { time_t now = time(0); tm* ltm = localtime(&now); int month = 1 + ltm->tm_mon; cout << "Current month: " << month << endl; return 0; }
#includeThis example uses the Boost Date/Time library to get the current local time using the second_clock::local_time() function. It then uses the date() function to extract the month value. The result is printed to the console. Both examples use different package libraries. Example 1 uses the built-in C++ libraries while Example 2 uses the Boost Date/Time library.#include using namespace std; using namespace boost::posix_time; int main() { ptime date = second_clock::local_time(); int month = date.date().month(); cout << "Current month: " << month << endl; return 0; }