diff options
| author | Daniel Andreas Wang <danielaw@relvokcor.xyz> | 2026-03-12 16:39:40 +0100 |
|---|---|---|
| committer | Daniel Andreas Wang <danielaw@relvokcor.xyz> | 2026-03-12 16:39:40 +0100 |
| commit | 6f966bd1132c476d9bf9c266e59f531cb3c26e27 (patch) | |
| tree | c882e5481cf560238eebc449b8234f7187a3fc15 /localutc.c | |
Diffstat (limited to 'localutc.c')
| -rw-r--r-- | localutc.c | 36 |
1 files changed, 36 insertions, 0 deletions
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 <stdio.h> +#include <time.h> + +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; +} |
