#include#include int main() { auto now = std::chrono::system_clock::now(); std::time_t t = std::chrono::system_clock::to_time_t(now); std::tm* tm = std::localtime(&t); int month = tm->tm_mon + 1; std::cout << "Current month is " << month << std::endl; return 0; }
#include#include #include int main() { auto now = std::chrono::system_clock::now(); std::time_t t = std::chrono::system_clock::to_time_t(now); std::tm* tm = std::localtime(&t); std::chrono::year_month_day date = std::chrono::year_month_day(std::chrono::year(tm->tm_year + 1900), std::chrono::month(tm->tm_mon + 1), std::chrono::day(tm->tm_mday)); std::cout << std::format("Formatted date: {:%Y-%m-%d}", date) << std::endl; return 0; }
#includeThis code creates two std::chrono::year_month_day objects representing two dates, and then compares them using the greater than operator. The result of the comparison is printed to the console. Package library:#include int main() { std::chrono::year_month_day first_date = std::chrono::year_month_day(std::chrono::year(2022), std::chrono::month(2), std::chrono::day(14)); std::chrono::year_month_day second_date = std::chrono::year_month_day(std::chrono::year(2022), std::chrono::month(3), std::chrono::day(1)); if (second_date > first_date) { std::cout << "Second date is greater than first date" << std::endl; } else { std::cout << "First date is greater than or equal to second date" << std::endl; } return 0; }