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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,693 questions

57,001 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 197 views
1 answer 350 views
1 answer 291 views
1 answer 246 views
1 answer 238 views
1 answer 405 views
1 answer 209 views
209 views asked Jun 13, 2020 by avibootz
...