I am trying to get the local datetime in a mqxlite project using code warrior 10.6. I do not want to use a NTP Server.
* I was using time.h, with a baseboard project. Unfortunately i don't think the implementation is available with kinetics.
* Tried _time_ticks_to_xdate - Could not trace the header.
in vain
Is there anyone who can help me get the current date/time.
Hello Srividhya Umashanker,
you can set it i.g. by this way:
void setTime(uint16_t year, uint16_t month, uint16_t day, uint16_t hour, uint16_t minute, uint16_t second, uint16_t timezone)
{
TIME_STRUCT timeStruct;
DATE_STRUCT dateStruct;
MQX_TICK_STRUCT_PTR ticks;
uint32_t rtc_time;
ticks = _mem_alloc(sizeof(MQX_TICK_STRUCT_PTR));
dateStruct.YEAR = year;
dateStruct.MONTH = month;
dateStruct.DAY = day;
dateStruct.HOUR = hour;
dateStruct.MINUTE = minute;
dateStruct.SECOND = second;
dateStruct.MILLISEC = 0;
if ( _time_from_date(&dateStruct, &timeStruct) == FALSE)
{
printf("\n Cannot convert date_time ");
}else{
rtc_time = timeStruct.SECONDS;
_time_set(&timeStruct);
_rtc_set_time(rtc_time);
_time_get_ticks(ticks);
_time_add_hour_to_ticks(ticks,timezone);
_time_set_ticks(ticks);
}
}
I hope it helps,
Iva
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------