How to Get LocalTime and Timezone

hello there,
i am developing an android game in which i change background as per time,
means if a player plays game during daytime then it will show light background, and if they play during night time then it will show dark background.

anyone knows how can i do that.
thank you in advance

1 Like

Get the local time using time() and convert it to a struct tm using localtime() and the current local hour is in tm_hour:

#include <time.h>

auto now = time(nullptr);
auto tm = localtime(&now);
unsigned currentHour = tm->tm_hour;

See another example at cppreference.com.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.