#include#include int main() { // Get the current date and time boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); // Print the current date and time std::cout << now << std::endl; return 0; }
#include#include int main() { // Create a date/time boost::posix_time::ptime datetime( boost::gregorian::date(2021, 7, 1), boost::posix_time::time_duration(12, 0, 0) ); // Add 1 hour datetime += boost::posix_time::hours(1); // Print the new date/time std::cout << datetime << std::endl; return 0; }
#includeThese examples use the Boost.DateTime library, which is part of the Boost C++ Libraries.#include int main() { // Create a date/time boost::posix_time::ptime datetime( boost::gregorian::date(2021, 7, 1), boost::posix_time::time_duration(12, 0, 0) ); // Format the date/time std::string formatted_datetime = boost::posix_time::to_simple_string(datetime); // Print the formatted date/time std::cout << formatted_datetime << std::endl; return 0; }