From 6f966bd1132c476d9bf9c266e59f531cb3c26e27 Mon Sep 17 00:00:00 2001 From: Daniel Andreas Wang Date: Thu, 12 Mar 2026 16:39:40 +0100 Subject: first commit --- localutc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 localutc.c (limited to 'localutc.c') diff --git a/localutc.c b/localutc.c new file mode 100644 index 0000000..3f2334e --- /dev/null +++ b/localutc.c @@ -0,0 +1,36 @@ +#include +#include + +int main() { + time_t now = time(NULL); + struct tm local_time, utc_time; + struct tm *temp; + char local_buffer[100]; + char utc_buffer[100]; + + // Get local time and copy it + temp = localtime(&now); + if (temp == NULL) { + fprintf(stderr, "Error: localtime() failed\n"); + return 1; + } + local_time = *temp; + + // Get UTC time and copy it + temp = gmtime(&now); + if (temp == NULL) { + fprintf(stderr, "Error: gmtime() failed\n"); + return 1; + } + utc_time = *temp; + + // Format into separate buffers + strftime(local_buffer, sizeof(local_buffer), "%Y-%m-%d %H:%M:%S", &local_time); + strftime(utc_buffer, sizeof(utc_buffer), "%Y-%m-%d %H:%M:%S", &utc_time); + + // Now print (order doesn't matter - data is safe) + printf("Local time: %s\n", local_buffer); + printf("UTC time: %s\n", utc_buffer); + + return 0; +} -- cgit