From 073a6396ef69fb23af66f053334158ae03842cb3 Mon Sep 17 00:00:00 2001 From: anon Date: Sun, 10 Mar 2024 15:57:35 +0100 Subject: [PATCH] Added current_year.cpp --- current_year.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 current_year.cpp diff --git a/current_year.cpp b/current_year.cpp new file mode 100644 index 0000000..4d5d866 --- /dev/null +++ b/current_year.cpp @@ -0,0 +1,20 @@ +// @COMPILECMD g++ $@ +#include +#include +#include + +int main() { + // Get the current system time + std::time_t currentTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + + // Convert the time to a local time + std::tm* localTime = std::localtime(¤tTime); + + // Extract the year from the local time + int currentYear = localTime->tm_year + 1900; + + // Display the current year + std::cout << "Current year: " << currentYear << std::endl; + + return 0; +}