Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

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 94 views
1 answer 200 views
1 answer 175 views
1 answer 129 views
1 answer 136 views
1 answer 281 views
1 answer 120 views
120 views asked Jun 13, 2020 by avibootz
...