Added current_year.cpp
This commit is contained in:
parent
ca7ab9b5e0
commit
073a6396ef
20
current_year.cpp
Normal file
20
current_year.cpp
Normal 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(¤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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user