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

1 Answer

0 votes
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int main() {
    // Set the timezone to London
    setenv("TZ", "Europe/London", 1);
    tzset();

    // Get the current time
    time_t now = time(NULL);
    struct tm *local = localtime(&now);

    printf("Current date and time in London: %02d-%02d-%04d %02d:%02d:%02d\n",
           local->tm_mday, local->tm_mon + 1, local->tm_year + 1900,
           local->tm_hour, local->tm_min, local->tm_sec);

    return 0;
}


/*
run:

Current date and time in London: 27-02-2025 07:45:34

*/

 



answered Feb 27, 2025 by avibootz

Related questions

1 answer 98 views
1 answer 245 views
1 answer 202 views
1 answer 148 views
1 answer 160 views
1 answer 307 views
1 answer 136 views
136 views asked Jun 13, 2020 by avibootz
...