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

kesha.modhia
Posts: 44
Joined: Fri May 13, 2022 12:36 pm

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

Postby kesha.modhia » Mon Jun 19, 2023 4:31 am

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


kesha.modhia
Posts: 44
Joined: Fri May 13, 2022 12:36 pm

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

Postby kesha.modhia » Thu Jun 22, 2023 5:55 am

Thanks for the suggestion
got the solutions

regards.

Who is online

Users browsing this forum: No registered users and 79 guests