fork download
  1. #include <iostream>
  2. #include <boost/date_time/posix_time/posix_time.hpp>
  3. #include <sstream> // For stringstream
  4.  
  5. int main() {
  6. // Get the current UTC time
  7. boost::posix_time::ptime utc_time = boost::posix_time::microsec_clock::universal_time();
  8.  
  9. // Extract the date part
  10. boost::gregorian::date today = utc_time.date();
  11.  
  12. // Use stringstream to format the date
  13. std::stringstream ss;
  14. ss << today.year()
  15. << std::setw(2) << std::setfill('0') << today.month().as_number()
  16. << std::setw(2) << std::setfill('0') << today.day();
  17.  
  18. // Convert the formatted string to int64_t
  19. int64_t date_numeric;
  20. ss >> date_numeric;
  21.  
  22. std::cout << "Date in YYYYMMDD format as integer: " << date_numeric << std::endl;
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
Date in YYYYMMDD format as integer: 20240422