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.

TM4C129XNCZAD: Display Time in 24 hour format instaed of A.M/P.M

Part Number: TM4C129XNCZAD

Dear Sir ,

I am using the example code of Tm4c129X  hibernation mode in our customize board.

Date time  display is working fine in AM and PM mode but i require date time in 24 hour format.

I have included date time.c file of example in our code.

First time bootup we are write the date time  as below

g_ui32DayIdx=15;
g_ui32MonthIdx=11;
g_ui32YearIdx=21;
g_ui32HourIdx=12;
g_ui32MinIdx=59;

DateTimeSet();

and read after every one second as below

bRTCUpdate = DateTimeDisplayGet(g_pcDateTimeBuf,sizeof(g_pcDateTimeBuf));
if(bRTCUpdate)
RTC_I_range_Update();

The date time display as 

15.11.2021 01.00  instead of 15.11.2021 13:00

I want to display Time in 24 hour directly  not in A.M/P.M

  • Hi,

      The DateTimeDisplayGet is a user function written in the example. DateTimeDisplayGet is not a TivaWare API. If you look at the DateTimeDisplayGet code in the calendar example, it will then call DateTimeGet(). DateTimeGet() finally calls the TivaWare API HibernateCalendarGet(). See below. HibernateCalendarGet will return the current time in a 24-hour representation. Therefore, there is no problem with TivaWare API HibernateCalendarGet(). 

    It is the DateTimeGet() user function that does post processing to produce AM/PM time instead of 24hour time. You are free to modify the example in the format you desire. Again, DateTimeGet() is a user function, not an TivaWare API.

    bool
    DateTimeGet(struct tm *sTime, char *pcAMPM)
    {
    //
    // Get the latest time.
    //
    HibernateCalendarGet(sTime);

    //
    // Is valid data read?
    //
    if(((sTime->tm_sec < 0) || (sTime->tm_sec > 59)) ||
    ((sTime->tm_min < 0) || (sTime->tm_min > 59)) ||
    ((sTime->tm_hour < 0) || (sTime->tm_hour > 23)) ||
    ((sTime->tm_mday < 1) || (sTime->tm_mday > 31)) ||
    ((sTime->tm_mon < 0) || (sTime->tm_mon > 11)) ||
    ((sTime->tm_year < 100) || (sTime->tm_year > 199)))
    {
    //
    // No - Let the application know the same by returning relevant
    // message.
    //
    return false;
    }

    //
    // Set AM as default.
    //
    strcpy(pcAMPM, "AM");

    //
    // Convert 24-hour format into 12-hour format with AM/PM indication.
    //
    if(sTime->tm_hour == 0)
    {
    sTime->tm_hour = 12;
    strcpy(pcAMPM, "AM");
    }
    else if(sTime->tm_hour == 12)
    {
    strcpy(pcAMPM, "PM");
    }
    else if(sTime->tm_hour > 12)
    {
    sTime->tm_hour -= 12;
    strcpy(pcAMPM, "PM");
    }

    //
    // Return that new data is available so that it can be displayed.
    //
    return true;
    }