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.

<time.h> gmtime On a Stellaris Device

Hello,

I'm developing on an EKS-lm4f232 and trying to keep track of the date and time using the included RTC.  I query the user for a date and time (MM/DD/YY HH:MM:SS), parse their string to make sure it's sensible and then fill out a tm structure with their information (http://www.cplusplus.com/reference/ctime/tm/).  

Ideally, I'd like to restrict the user to only entering GMT time.  Obviously, they can choose to enter whatever they please, but this leads me to my question.  I take the filled in tm structure, use mktime to get a time_t to seed my RTC with, and then use localtime to print out the date and time they've entered.  When I use localtime, I get back exactly the date and time the user has entered (ideal), but when I use gmtime to do the same thing, the hours field gets adjusted even when the inputted time is, in fact, GMT.  It seems logical that, if I want to keep track of GMT, I should use the gmtime function, but this behavior is confusing me.  I don't see a timezone field in struct tm that I can adjust.  Can anyone help me understand what's going on here?  

-David

eks-lm4f232

  • I presume you are using the time functions that come with the TI ARM compiler.

    You probably ought to become familiar with the implementation of the function gmtime.  It is in the file gmtime.c, which can be found in the zip file compiler install root\lib\rtssrc.zip.  You'll see that it adds the value _tz.timezone to the time passed in, then returns it.  The structure _tz is initialized in the file tmzone.c.  There you can see the timezone field is initialized to the value 21600.  This the number of seconds in 6 hours.  I'm not certain, but I'm pretty sure that's because the compiler developers are in the US Central time zone, and GMT is 6 hours ahead (with rare exceptions).  

    It is likely that this simple implementation of gmtime is not sufficient for your application, and you need to change it.

    Thanks and regards,

    -George