time: display local time

This commit is contained in:
Dave Murphy 2024-10-18 19:30:12 +01:00
parent 399aa26c6e
commit 5e36dc2902
No known key found for this signature in database
GPG Key ID: F7FD5492264BB9D0

View File

@ -1,5 +1,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <time.h> #include <time.h>
#include <switch.h> #include <switch.h>
@ -20,6 +21,7 @@ int main(int argc, char **argv)
padInitializeDefault(&pad); padInitializeDefault(&pad);
printf("\x1b[16;16HPress PLUS to exit."); printf("\x1b[16;16HPress PLUS to exit.");
printf("\x1b[17;16HTZ=%s\n", getenv("TZ"));
// Main loop // Main loop
while(appletMainLoop()) while(appletMainLoop())
@ -34,7 +36,7 @@ int main(int argc, char **argv)
//Print current time //Print current time
time_t unixTime = time(NULL); time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);//Gets UTC time. If you want local-time use localtime(). struct tm* timeStruct = localtime((const time_t *)&unixTime); // Gets local time. If you want UTC use gmtime().
int hours = timeStruct->tm_hour; int hours = timeStruct->tm_hour;
int minutes = timeStruct->tm_min; int minutes = timeStruct->tm_min;