Computing.Net > Forums > Unix > How to format difftime?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to format difftime?

Reply to Message Icon

Name: Jeab
Date: August 27, 2003 at 21:47:11 Pacific
OS: UNIX
CPU/Ram: 256
Comment:

I already found difftime between now and the highest value of time_t. I would like to know how I can format the value into years, months, days, hours, and minutes.

Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 27, 2003 at 22:56:53 Pacific
Reply:

Hi:

Take a look at the tm structure in the time.h header file. Here's a stub program using some of the functions:

Regards,

Nails

#include
#include

main()
{
struct tm *old, *new;
time_t tloc, newtloc; /* generally time_t is a long */

time(&tloc); /* get time in seconds since EPOCH */
printf("time in seconds since EPOCH is %ld\n", tloc);

old=localtime(&tloc); /* convert seconds to date structure */
printf("year is %d\n",old->tm_year);
printf("month is %d\n",old->tm_mon+1);
printf("day is %d\n",old->tm_mday);
printf("hour is %d\n",old->tm_hour);
printf("min is %d\n",old->tm_min);

new=old;

newtloc=mktime(new); /* convert structure to seconds */

if(newtloc == tloc)
printf("they're equal\n");

}


0
Reply to Message Icon

Related Posts

See More


binary to ASCII Group differs in



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: How to format difftime?

how to get the last field www.computing.net/answers/unix/how-to-get-the-last-field/6529.html

How to Remove LILO from Windows NT boot www.computing.net/answers/unix/how-to-remove-lilo-from-windows-nt-boot-/2230.html

How to pad spaces www.computing.net/answers/unix/how-to-pad-spaces/3892.html