0
Why my time is not correct
My time shows 5h:30m back https://code.sololearn.com/c5IVEy1W4loE/?ref=app
3 odpowiedzi
+ 3
+ 3
The __TIME__ macro gives the time according to UTC. India is 5:30 hours ahead of UTC, so your code will output the time 5 hours and 30 minutes behind your local time (I don't know how you're getting 2h:30m back).
To get the local time, first get the current time using the time() function of the <time.h> header. Then convert it to local time using the localtime() function.
Note that this approach will not work on SoloLearn as SoloLearn runs the code on remote servers located somewhere in the world. So the code will output the time for that place. The simplest way to deal with this is to set the environment variable TZ to your timezone (Asia/Kolkata for India).
Example:
https://code.sololearn.com/csqx4ad2u3iF/?ref=app
+ 1
Thanks XXX for this , it is really helpful to understand about time
My mistake for 2:30 it's actually 5:30 😀😀