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.

Issue converting time to timestamp



I am coding in C++ in CCS6.1.1

the include directory points to ~/ti/ccsv6/tools/compiler/ti-cgt-msp430_4.4.5/include

tm Tm;

// set every field to zero
Tm.tm_sec = 0;      /* seconds after the minute   - [0,59]  */
Tm.tm_min = 0;      /* minutes after the hour     - [0,59]  */
Tm.tm_hour = 0;     /* hours after the midnight   - [0,23]  */
Tm.tm_mday = 0;     /* day of the month           - [1,31]  */
Tm.tm_mon = 0;      /* months since January       - [0,11]  */
Tm.tm_year = 0;     /* years since 1900                     */
Tm.tm_wday = 0;     /* days since Sunday          - [0,6]   */
Tm.tm_yday = 0;     /* days since Jan 1st         - [0,365] */
Tm.tm_isdst = 0;    /* Daylight Savings Time flag           */

Tm.tm_year = 46;
Tm.tm_mon = 2;
Tm.tm_day = 23;
Tm.tm_hour = 9;
Tm.tm_min = 3;
Tm.tm_sec = 38;

   time_t epoch = mktime(&Tm);

epoch => 1458651818
going to: http://www.epochconverter.com/

outputs:

Tue 22 Mar 2016 09:03:38 AM EDT GMT-4:00 DST

WHY? I am setting day to 23, not 22, why is my epoch converting to 23rd? What
is the recommended way to fix it?

But if I set the year to 116, my result is even worse.  Am I doing something wrong?

EDIT:

I tried the following on my Linux machine:

#include <stdio.h>
#include <time.h>

int main() {
    // set every field to zero
    tm Tm;
    Tm.tm_sec = 0;      /* seconds after the minute   - [0,59]  */
    Tm.tm_min = 0;      /* minutes after the hour     - [0,59]  */
    Tm.tm_hour = 0;     /* hours after the midnight   - [0,23]  */
    Tm.tm_mday = 0;     /* day of the month           - [1,31]  */
    Tm.tm_mon = 0;      /* months since January       - [0,11]  */
    Tm.tm_year = 0;     /* years since 1900                     */
    Tm.tm_wday = 0;     /* days since Sunday          - [0,6]   */
    Tm.tm_yday = 0;     /* days since Jan 1st         - [0,365] */
    Tm.tm_isdst = 0;    /* Daylight Savings Time flag           */

    Tm.tm_year = 116;
    Tm.tm_mon = 2;
    Tm.tm_mday = 23;
    Tm.tm_hour = 9;
    Tm.tm_min = 3;
    Tm.tm_sec = 38;

    time_t epoch = mktime(&Tm);

    printf("Epoch is: %ld\n", epoch);
    return 0;
}

This worked fine on my Linux machine using Linux time.h, result is 1458741818, converting it at http://www.epochconverter.com/ produces  `Wed 23 Mar 2016 10:03:38`

The same code snippet on MSP430 using ti-cgt-map430_4.4.5 produces result: 3667712618, converting it produces `Sat 23 Mar 2086 05:03:38 AM EDT GMT-4:00 DST`

Is there an issue with the Library?