1

i need to get the epoch time for the date and time enter, but when i enter like 2048(year), i am getting very large value, "18446744073709551615", which is supposed to be incorrect..

when i enter the date like 2012(year), 2015(year), it epoch value is correct, any changes i need to do for the 2048 (year)

time_t get_unix_time(int,int,int,int,int,int,int);
int main()
{
unsigned long long m_process_date;
m_process_date = get_unix_time (12,31,2048,23,59,58,-1);
std::cout<<"\n m_process_date:"<< m_process_date<<std::endl;
return 1;
}


time_t get_unix_time(   int         month,
                        int         day,
                        int         year,
                        int         hour,
                        int         minute,
                        int         second,
                        int         dst )
{
    tm          ts;

    ts.tm_mon = month - 1;
    ts.tm_mday = day;

    if( year < 100 )
        ts.tm_year = year + 100;
    else
        ts.tm_year = year - 1900;

    ts.tm_hour = hour;
    ts.tm_min = minute;
    ts.tm_sec = second;
    ts.tm_isdst = dst;

    return mktime( &ts );
}
Gopal
  • 757
  • 3
  • 13
  • 30
  • 1
    Often time is still measured in a signed 32-bit number of seconds from 1970. This means that in 2038 time will overflow. See e.g. [the year 2038 problem](http://en.wikipedia.org/wiki/2038_problem). – Some programmer dude Feb 13 '13 at 09:28
  • ...as I was typing. :) – Dacto Feb 13 '13 at 09:31
  • Does your platform support mktime64 (the 64-bit version of mktime) ? http://stackoverflow.com/questions/7914368/64-bit-unix-timestamp-conversion – selbie Feb 13 '13 at 09:37
  • IF you have the option, compile as 64 bit. The newer 64 bit runtimes store time_t values as 64 bit unsigned integers. – jim mcnamara Feb 13 '13 at 15:15

1 Answers1

2

The standard Unix time is stored in a signed int. This is normal 32-bits but may differ depending on implementation (some new implementations store time_t as signed 64-bit int).

Thus, for a 32-bit signed int, this means the maximum representable date would be Jan 19, 2038.

Dacto
  • 2,901
  • 9
  • 45
  • 54
  • If you used the 64-bit representation then you can have a maximum date of nearly 300 billion years. – Dacto Feb 16 '13 at 01:30
  • the issue is that some machine are in 32 bit and some are in 64 bit.. i need to code for 32 bit and then release it too 64 bit – Gopal Feb 20 '13 at 12:46