How to get the current date and time in London with C++

1 Answer

0 votes
#include <iostream>
#include <chrono>
#include <iomanip> // put_time

int main() {
    // Get the current time as a time_point
    auto now = std::chrono::system_clock::now();

    // Convert to time_t to get calendar time
    std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);

    // Convert to tm structure for UTC
    std::tm utc_tm = *std::gmtime(&now_time_t);

    // Adjust for London time 
    std::tm london_tm = utc_tm;

    std::cout << "Current date and time in London: "
              << std::put_time(&london_tm, "%Y-%m-%d %H:%M:%S") << std::endl;
}



/*
run:
     
Current date and time in London: 2025-02-27 06:57:27
     
*/
 

 



answered Feb 27, 2025 by avibootz
edited Feb 27, 2025 by avibootz

Related questions

1 answer 111 views
1 answer 232 views
1 answer 194 views
1 answer 139 views
1 answer 153 views
1 answer 302 views
1 answer 133 views
133 views asked Jun 13, 2020 by avibootz
...