Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unix longtime 2099

Status
Not open for further replies.

kasavazala

Programmer
Joined
Jul 25, 2003
Messages
7
Location
US
Can anyone tell me how to get the unix long time for the date 01/01/2099. when i am trying to use mktime from a c program, I am getting -1.
this is the chunk of code i am using
struct tm *tm;
time_t l;
int i;
long ptm;

l = time(&i);
tm = localtime(&i);

tm->tm_year=2099-1900;
tm->tm_mon=0;
tm->tm_mday=1;
tm->tm_hour=0;
tm->tm_sec=0;
tm->tm_min=0;

ptm = mktime(tm);

printf("%ld\n",ptm);

is giving me -1.

thanks in advance.
 
What operating system are you on?

On Solaris for example, from the mktime() man page:

[tt] The tm_year member must be for year 1901 or later. Calendar
times before 20:45:52 UTC, December 13, 1901 or after
03:14:07 UTC, January 19, 2038 cannot be represented. Port-
able applications should not try to create dates before
00:00:00 UTC, January 1, 1970 or after 00:00:00 UTC, January
1, 2038.[/tt]



Annihilannic.
 
The reason you are getting -1 is mktime return -1 if it cannot convert the tm struct to an epoch time. In other words -1 means there is no epoch time representation of 1-Jan-2099 beacuse it would overflow the 32-bit int used to store epoch time. Annihilannic's post gives the acceptable date ranges. I have never seen a unix system that allows 2099 to be converted w/ standard time functions. That being the case I know of no way for mktime to decode that date.

Sorry I don't have a better answer for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top