Page 1 of 1

How to fetch real world time using NTP server, I am getting root time ie. 1 jan,1970

Posted: Mon Jun 19, 2023 4:31 am
by kesha.modhia
Here i have attached piece of code which i have used to get the real world time but the time i am getting is base time which is shown as output below

how to get the current time

Input :

#inlcude<time.h>

time_t now;
char strftime_buf[64];
struct tm timeinfo;

time(&now);
// Set timezone to India Standard Time
setenv("TZ", "UTC-5:30", 1);
tzset();

localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
ESP_LOGI(TAG, "The current date/time in India is: %s", strftime_buf);



Output :
I (05:30:28.084)example.c: The current date/time in India is: Thu Jan 1 05:30:28 1970

Re: How to fetch real world time using NTP server, I am getting root time ie. 1 jan,1970

Posted: Mon Jun 19, 2023 9:34 am
by MicroController

Re: How to fetch real world time using NTP server, I am getting root time ie. 1 jan,1970

Posted: Thu Jun 22, 2023 5:55 am
by kesha.modhia
Thanks for the suggestion
got the solutions

regards.