linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Unix Time
@ 2004-09-26 14:02 Ankit Jain
  2004-09-27  3:01 ` Suciu Flavius
  0 siblings, 1 reply; 7+ messages in thread
From: Ankit Jain @ 2004-09-26 14:02 UTC (permalink / raw)
  To: linux prg

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unix Time
  2004-09-27  3:01 ` Suciu Flavius
@ 2004-09-26 22:57   ` Jon Masters
  2004-09-27  5:10     ` Ankit Jain
  0 siblings, 1 reply; 7+ messages in thread
From: Jon Masters @ 2004-09-26 22:57 UTC (permalink / raw)
  To: Suciu Flavius; +Cc: linux-c-programming

On Sun, 26 Sep 2004 20:01:04 -0700, Suciu Flavius
<suciuflavius@tiscali.de> wrote:

>   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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unix Time
  2004-09-26 14:02 Unix Time Ankit Jain
@ 2004-09-27  3:01 ` Suciu Flavius
  2004-09-26 22:57   ` Jon Masters
  0 siblings, 1 reply; 7+ messages in thread
From: Suciu Flavius @ 2004-09-27  3:01 UTC (permalink / raw)
  To: linux-c-programming


  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);













Ankit Jain wrote:
> 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unix Time
  2004-09-26 22:57   ` Jon Masters
@ 2004-09-27  5:10     ` Ankit Jain
  2004-09-27 10:59       ` szonyi calin
  0 siblings, 1 reply; 7+ messages in thread
From: Ankit Jain @ 2004-09-27  5:10 UTC (permalink / raw)
  To: jonathan; +Cc: linux prg

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


 --- Jon Masters <jonmasters@gmail.com> wrote: 
> On Sun, 26 Sep 2004 20:01:04 -0700, Suciu Flavius
> <suciuflavius@tiscali.de> wrote:
> 
> >   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.
> -
> To unsubscribe from this list: send the line
> "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unix Time
  2004-09-27  5:10     ` Ankit Jain
@ 2004-09-27 10:59       ` szonyi calin
  2004-09-27 11:57         ` Jon Masters
  0 siblings, 1 reply; 7+ messages in thread
From: szonyi calin @ 2004-09-27 10:59 UTC (permalink / raw)
  To: Ankit Jain; +Cc: linux prg

 --- Ankit Jain <ankitjain1580@yahoo.com> a écrit : 
> 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

> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unix Time
  2004-09-27 10:59       ` szonyi calin
@ 2004-09-27 11:57         ` Jon Masters
  2004-09-27 21:33           ` Sumit Narayan
  0 siblings, 1 reply; 7+ messages in thread
From: Jon Masters @ 2004-09-27 11:57 UTC (permalink / raw)
  To: szonyi calin; +Cc: Ankit Jain, linux prg

On Mon, 27 Sep 2004 12:59:47 +0200 (CEST), szonyi calin
<caszonyi@yahoo.com> wrote:

> 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unix Time
  2004-09-27 11:57         ` Jon Masters
@ 2004-09-27 21:33           ` Sumit Narayan
  0 siblings, 0 replies; 7+ messages in thread
From: Sumit Narayan @ 2004-09-27 21:33 UTC (permalink / raw)
  To: jonathan; +Cc: szonyi calin, Ankit Jain, linux prg

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

On Mon, 27 Sep 2004 12:57:42 +0100, Jon Masters <jonmasters@gmail.com> wrote:
> On Mon, 27 Sep 2004 12:59:47 +0200 (CEST), szonyi calin
> <caszonyi@yahoo.com> wrote:
> 
> > 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-09-27 21:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-26 14:02 Unix Time Ankit Jain
2004-09-27  3:01 ` Suciu Flavius
2004-09-26 22:57   ` Jon Masters
2004-09-27  5:10     ` Ankit Jain
2004-09-27 10:59       ` szonyi calin
2004-09-27 11:57         ` Jon Masters
2004-09-27 21:33           ` Sumit Narayan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).