getting and useing system time 
Author Message
 getting and useing system time

ok here's my prob.
is there a premade call so my program can get the time displayed and used by
the system, then act on that time?
also
is there a call or pre-done api that will allow me to use seconds to control
actions (each second something would happen)

ive seen something searching around to the likeness of time_t (time_t * t) I
had first figured that this was a built in call, but it sadly had no
explanation as to how and where to use it, and after fooling with it I came
to the conclusion that it was not as I had figured,
so if anyone can help me with this I would be greatly appreciative
thanks



Tue, 13 Jul 2004 03:51:40 GMT  
 getting and useing system time
http://www.eskimo.com/~scs/C-faq/q13.12.html


Tue, 13 Jul 2004 08:19:31 GMT  
 getting and useing system time


)ok here's my prob.
)is there a premade call so my program can get the time displayed and used by
)the system, then act on that time?
)also
)is there a call or pre-done api that will allow me to use seconds to control
)actions (each second something would happen)
)
)
)ive seen something searching around to the likeness of time_t (time_t * t) I
)had first figured that this was a built in call, but it sadly had no
)explanation as to how and where to use it, and after fooling with it I came
)to the conclusion that it was not as I had figured,
)so if anyone can help me with this I would be greatly appreciative
)thanks

The answer is: Not with ANSI C. Your system may have a way to do what
you want, but you'll need to ask in a system specific newsgroup.

Mike

--
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
I can explain it for you, but I can't understand it for you.
I don't speak for Alcatel      <- They make me say that.



Tue, 13 Jul 2004 04:49:32 GMT  
 getting and useing system time



Quote:


> )ok here's my prob.
> )is there a premade call so my program can get the time displayed and used
by
> )the system, then act on that time?
> )also
> )is there a call or pre-done api that will allow me to use seconds to
control
> )actions (each second something would happen)
> )
> )
> )ive seen something searching around to the likeness of time_t (time_t *
t) I
> )had first figured that this was a built in call, but it sadly had no
> )explanation as to how and where to use it, and after fooling with it I
came
> )to the conclusion that it was not as I had figured,
> )so if anyone can help me with this I would be greatly appreciative
> )thanks

> The answer is: Not with ANSI C. Your system may have a way to do what
> you want, but you'll need to ask in a system specific newsgroup.

Nothing like not answering the questions!

time_t time(time_t *);

it returns the time in seconds since Jan 1st 1970 [I think in GMT time].

on most platforms you can manage

unsigned long a = time(NULL);
printf("%lu\n", a);

I forget what time_t translates to directly but on alot of platforms that
works, at least you will see it working :-)

Tom



Fri, 16 Jul 2004 19:43:03 GMT  
 getting and useing system time

Quote:



> > )is there a premade call so my program can get the time displayed and used
> > )by the system, then act on that time?
> > )also is there a call or pre-done api that will allow me to use seconds to
> > )control actions (each second something would happen)

> > The answer is: Not with ANSI C. Your system may have a way to do what
> > you want, but you'll need to ask in a system specific newsgroup.

> Nothing like not answering the questions!

...except answering them incorrectly.

Quote:
> time_t time(time_t *);

> it returns the time in seconds since Jan 1st 1970 [I think in GMT time].

Wrong. It does so on POSIX systems. It doesn't do so under normal,
non-POSIX MS-DOS compilers, and probably not under MS-Windows, either.
It doesn't do so on a lot of systems.

Quote:
> on most platforms you can manage

> unsigned long a = time(NULL);
> printf("%lu\n", a);

On many, but there's no guarantee whatsoever of the meaning of the value
displayed. However, if you do this:

  time_t tt;

  tt=time(0); /* Or even simply time(&t); */
  puts(ctime(tt));

you are guaranteed to get a text representation of the implementation's
best approximation of current local time.
Note that the buffer used by ctime() is static to that function, and
will be overwritten by the next call to ctime(); so copy it if you need
it later.
If you're more interested in the numerical count of hours, minutes and
seconds, you can use localtime() or gmtime() to translate a time_t into
a struct tm. The other way 'round can be done with mktime(). And if you
prefer the number of seconds since some moment, have a look at
difftime().
All these functions _are_ ISO C, _are_ portable, and _are_ dependable,
unlike Tom's broken hack.

Even then, there is no ISO C way to answer the second of Mr. K's
questions. To do this usefully, you would need threads or something
similar - otherwise, what happens to your counter while you're waiting
for input? And threads are beyond the scope of the ISO C Standard.

Quote:
> I forget what time_t translates to directly

Neither does the Standard specify anything more than "a representation
of time", so it is just as well you don't.

Quote:
> but on alot of platforms that

"A lot", dammit, "a lot". Not "alot". Why, by the unrelenting
eyeball-sucking demons of R'Lyeh, do so many clueless Merkins get this
wrong? It's not as if it is so hard, {*filter*}y 'ell.

Richard



Fri, 16 Jul 2004 20:55:34 GMT  
 getting and useing system time
check out the gettimeofday system call in unix


Fri, 16 Jul 2004 23:51:51 GMT  
 getting and useing system time

Quote:
> check out the gettimeofday system call in unix

And what if someone, somewhere, (God forbid) uses something *other* than
Unix?

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"'I' is the most beautiful word in the world."
   - John Nordberg



Fri, 16 Jul 2004 23:53:49 GMT  
 getting and useing system time

Quote:

> check out the gettimeofday system call in unix

Or rather, don't. It isn't likely to perform a service you can't get any
ISO C way, and it makes your program unportable.

Richard



Sat, 17 Jul 2004 00:06:20 GMT  
 getting and useing system time
On Mon, 28 Jan 2002 11:43:03 GMT, "Tom St Denis"

Quote:





>> )ok here's my prob.
>> )is there a premade call so my program can get the time displayed and used
>by )the system, then act on that time?
>> The answer is: Not with ANSI C. Your system may have a way to do what
>> you want, but you'll need to ask in a system specific newsgroup.

>Nothing like not answering the questions!

>time_t time(time_t *);

>it returns the time

Tom, the question was to get hte time and then /do/ something. In
other words the OP requires a scheduler.
To the OP: you want something like task scheduler or cron. You'd
better search your systems online help for that.

Quote:
>in seconds since Jan 1st 1970 [I think in GMT time].

Nope, as others have pointed out.

Quote:
>on most platforms you can manage

>unsigned long a = time(NULL);
>printf("%lu\n", a);

Since time returns an arithmetic type not an integer, this is
potentially menaingless.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>



Sat, 17 Jul 2004 06:23:50 GMT  
 getting and useing system time

Quote:
>Nothing like not answering the questions!

Sometimes answering them is worse.

Quote:
>time_t time(time_t *);

>it returns the time in seconds since Jan 1st 1970 [I think in GMT time].

It returns the time in the form of a time_t.  There is no guarantee
that a time_t is in the form of "number of <time unit> since <epoch time>".
ANSI C does not include POSIX.

For example, one possible implementation of a time_t could be
HHMMSSmmDDYYYYY, treated as a decimal number (but it won't fit into
32 bits), where HH = hour of the day, MM = minute, SS = second, mm
= month (1-12), DD = day of the month, and YYYYY = year (5 digits!).
Note carefully that subtracting two time_t's of this form yields
useless garbage, and that trying to compare them as two numbers
does not give useful information about which happened earlier.
(the standards way to compute time differences is difftime(), which
for this representation will not be a trivial function.)

Some functions useful for formatting the time into human-readable
form include localtime(), asctime(), ctime(), and strftime().

                                                Gordon L. Burditt



Mon, 04 Oct 2004 14:52:43 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Getting Desparete, Is anyone useing IPX/SPX with CSocketFile

2. Useing dbbind with Date/Time Fields

3. getting system time on NT

4. Getting system time

5. getting wrong system time

6. getting the system time format

7. Getting idle time of system/os

8. Getting system date/time at midnight?

9. runtime needed (getting system time?)

10. Getting system time from an NT server

11. Getting current system time in milliseconds

12. Minimum Wait Time (System Time Resolution)

 

 
Powered by phpBB® Forum Software