Added current_year.cpp

This commit is contained in:
anon 2024-03-10 15:57:35 +01:00
parent ca7ab9b5e0
commit 073a6396ef

20
current_year.cpp Normal file
View File

@ -0,0 +1,20 @@
// @COMPILECMD g++ $@
#include <iostream>
#include <chrono>
#include <ctime>
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(&currentTime);
// 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;
}