This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to convert date and time to timestamp?

Hi, I use IoT sdk with my iPhone to get current date and time, date comes in ble_cts_c_evt_t structure, how can I convert it to timestamp, I know that I have to subscribe Jan 1, 1970 from current date and multiple all by 84600, but maybe is there more trivial way?

Parents Reply Children
  • If I use mktime, I get incorrect data

    struct tm time_struct;
    ble_date_time_t datetime = p_evt->params.current_time.exact_time_256.day_date_time.date_time;
    time_t newtime;
    time_struct.tm_year = datetime.year - 1900;
    time_struct.tm_mon = datetime.month;
    time_struct.tm_mday = datetime.day;
    time_struct.tm_hour = datetime.hours;
    time_struct.tm_min = datetime.minutes;
    time_struct.tm_sec = datetime.seconds;
    newtime = mktime(&time_struct);
    
    NRF_LOG_INFO("Timestamp is %ld\r\n", newtime); // got tomorrow day
    
    

Related