Skip to contentSkip to conversation

Unix Time

DISCUSSION Ankit Jain 5 participants 7 messages Sep 26, 2004 – Sep 27, 2004

lore
Share & tools
lore

Ankit Jain

author
#0 lore raw

well i dont know hot to interpret unix time

gettimeofday returns time in unix format

if i am want to subtract one time from another how to do that?

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html

#2 lore raw
In reply to Suciu Flavius
Quoted 11 lines · Suciu Flavius

struct timeval start,stop;
int elapsed;

  gettimeofday(&start,NULL);

  computeWhatIWant();

  gettimeofday(&stop,NULL);

elapsed=(stop.tv_sec-start.tv_sec)*1000000+(stop.tv_usec-start.tv_usec); printf("sprintf: elapsed=%5d miliseconds\n",elapsed);

...or you could use the POSIX difftime function if you don't mind having a double returned.

Jon.

#1 lore raw
In reply to Ankit Jain

struct timeval start,stop;
int elapsed;

gettimeofday(&start,NULL);

computeWhatIWant();

gettimeofday(&stop,NULL);

elapsed=(stop.tv_sec-start.tv_sec)*1000000+(stop.tv_usec-start.tv_usec); printf("sprintf: elapsed=%5d miliseconds\n",elapsed);

Quoted 18 lines · Ankit Jain

well i dont know hot to interpret unix time

gettimeofday returns time in unix format

if i am want to subtract one time from another how to do that?

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now http://uk.messenger.yahoo.com/download/index.html
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#3 lore raw
In reply to Jon Masters

well still the problem exists

7360568 sec how to interpret this no. in seconds?

do u know about any manula to understand htis unix time

thanks

ankit

Quoted 6 lines · --- Jon Masters
Quoted 3 lines · Suciu Flavius

struct timeval start,stop;
int elapsed;

Quoted 8 lines
Quoted 7 lines
  gettimeofday(&start,NULL);

  computeWhatIWant();

  gettimeofday(&stop,NULL);

elapsed=(stop.tv_sec-start.tv_sec)*1000000+(stop.tv_usec-start.tv_usec);

Quoted 7 lines
Quoted 1 line

printf("sprintf: elapsed=%5d

miliseconds\n",elapsed);

...or you could use the POSIX difftime function if you don't mind
having a double returned.

Quoted 8 lines

Jon.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html

#4 lore raw

--- Ankit Jain <[email protected]> a écrit :

Quoted 7 lines

well still the problem exists

7360568 sec how to interpret this no. in seconds?

do u know about any manula to understand htis unix time

The linux's libc manual covers afaik the topic of time functions in linux/unix
also here you may find some informartion
http://www.unix.org/single_unix_specification/onlinepubs/000095399/functions/contents.html

to convert a number of secconds in actual time:
a minute has 60 seconds
an hour has 60 minutes = 3600 seconds
a day has 24 hours = 86400 seconds

Hope this helps

Quoted 6 lines

thanks

ankit

=====
--
A mouse is a device used to point at
the xterm you want to type in.
Kim Alm on a.s.r.

Vous manquez d’espace pour stocker vos mails ? Yahoo! Mail vous offre GRATUITEMENT 100 Mo ! Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour dialoguer instantanément avec vos amis. A télécharger gratuitement sur http://fr.messenger.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 4 lines · szonyi calin

to convert a number of secconds in actual time:
a minute has 60 seconds
an hour has 60 minutes = 3600 seconds
a day has 24 hours = 86400 seconds

...but don't use this because over the period of seconds since epoch (January 1 1970 is when UNIX began counting time) it'll not take in to account leap seconds and the like - so you'll cunningly be out of time by a little in every calculation.

No. Use the standard POSIX time functions instead - e.g. localtime() to give you the view of time for where you are in the world.

Cheers,

Jon.

#6 lore raw

You can use ctime() for conversion.

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

int main(){
time_t a;
printf("%d = ", time(&a));
printf("%s\n", ctime(&a));
return 0;
}

Hope this helps.

--Sumit

Quoted 26 lines · Jon Masters
Quoted 4 lines · szonyi calin

to convert a number of secconds in actual time:
a minute has 60 seconds
an hour has 60 minutes = 3600 seconds
a day has 24 hours = 86400 seconds

...but don't use this because over the period of seconds since epoch (January 1 1970 is when UNIX began counting time) it'll not take in to account leap seconds and the like - so you'll cunningly be out of time by a little in every calculation.

No. Use the standard POSIX time functions instead - e.g. localtime() to give you the view of time for where you are in the world.

Cheers,

Jon.

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html