This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1294NCPDT: Setting timezone inside the code from the time.h header file

Part Number: TM4C1294NCPDT


Dear TI members,

I was trying to convert the UTC time obtained from a remote NTP server to my local time for which I have used the following function code:

void setTime(uint32_t t)
{
    time_t ts;
    struct tm tm;
    struct tm td;

    Seconds_set(t);

    time(&ts);
    tm = *localtime(&ts);

    System_printf("NTP Server time: %s\n", asctime(&tm));

    System_flush();
}

Here I am getting again the UTC time and the localtime function is not able to convert the UTC time to the local time as the function name suggests.

I tried to get to its root cause so I find that there is a timezone structure inside the time.h header file but it only has the data structure of it and no function to operate on that data structure.

Here is the code snippet from the time.h file of the timezone data structure:

/*************************************************************************/
/* TIME ZONE STRUCTURE DEFINITION                                        */
/*************************************************************************/
typedef struct 
{
    short daylight;
    long  timezone; /* seconds WEST of UTC.  Strange but traditional */
    char  tzname[4];
    char  dstname[4];
} TZ;

extern _DATA_ACCESS TZ _tz;

So , I want to know that how can I use this timezone data structure and how can I make the localtime function to return the local time of my region.

regards

  • Does it not appear that the 'timezone' value (likely) has been cleared?     If  zero seconds are added to UTC/GMT - 'UTC' (IS) 'expected!'

    Comment directs that 'timezone' should be loaded w/the, "Difference in hours (converted to seconds [hours * 3600] - between your timezone - and GMT - when moving west from GMT."    

    Note: we've not employed that function - this response is based upon the (hopefully) logical use of the data you've presented...