#include <iostream>
#include <chrono>
#include <format>
#include <string>
#include <map>
using namespace std::chrono; // current_zone / zoned_time / system_clock
int main() {
// Map user choices to IANA time zone names
std::map<int, std::string> timezones = {
{1, "America/Anchorage"}, // Alaska
{2, "America/Guatemala"}, // Central America
{3, "America/Godthab"}, // Greenland
{4, "Europe/Paris"}, // Paris
{5, "Asia/Shanghai"} // Beijing
};
std::cout << "Choose a timezone to convert your local time:\n"
<< "1. Alaska (-9:00 UTC)\n"
<< "2. Central America (-6:00 UTC)\n"
<< "3. Greenland (-3:00 UTC)\n"
<< "4. Paris (+1:00 UTC)\n"
<< "5. Beijing (+8:00 UTC)\n"
<< "Enter your choice (1-5): ";
int choice;
std::cin >> choice;
if (timezones.find(choice) == timezones.end()) {
std::cout << "Invalid choice.\n";
return 1;
}
// Get current local time
auto local_zone = current_zone();
auto local_time = zoned_time{local_zone, system_clock::now()};
std::cout << "Local time: " << format("{:%F %T %Z}", local_time) << '\n';
// Convert to selected time zone
auto target_zone = locate_zone(timezones[choice]);
auto target_time = zoned_time{target_zone, local_time.get_sys_time()};
std::cout << "Converted time (" << timezones[choice] << "): "
<< format("{:%F %T %Z}", target_time) << '\n';
}
/*
run:
Choose a timezone to convert your local time:
1. Alaska (-9:00 UTC)
2. Central America (-6:00 UTC)
3. Greenland (-3:00 UTC)
4. Paris (+1:00 UTC)
5. Beijing (+8:00 UTC)
Enter your choice (1-5): 3
Local time: 2025-11-01 08:51:09.259509992 UTC
Converted time (America/Godthab): 2025-11-01 06:51:09.259509992 -02
*/