Hello,
I am using the Lwip Stack in my software and integrated SNTP.c and .h file in my project.
I have debugged the software and found that whenever control hit the break point at below line
static void
sntp_process(u32_t *receive_timestamp)
{
/* convert SNTP time (1900-based) to unix GMT time (1970-based)
* @todo: if MSB is 1, SNTP time is 2036-based!
*/
time_t t = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970);
}
We get seconds value in 't' instance. for example t = 1518585734
my question is, how should i convert the unix time to UTC time (YY:MM:DATE:HR:MIN:SEC). is there any ready made function available?
Shall i use following code?
static void
sntp_process(u32_t *receive_timestamp)
{
/* convert SNTP time (1900-based) to unix GMT time (1970-based)
* @todo: if MSB is 1, SNTP time is 2036-based!
*/
time_t timenow = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970);
// Format time, "ddd yyyy-mm-dd hh:mm:ss zzz"
struct tm ts;
char buf[80];
ts = *localtime(&timenow);
strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
}
please advice.