Getting current date and time.

Getting current date and time.

Post by Fran?ois BARDI » Wed, 20 Aug 1997 04:00:00



hye,
does anybody know how to get the current time & date settings ?
I've tried using ctime(3), but i can't get it.
thanks in advance,

                        julian.

 
 
 

Getting current date and time.

Post by Kurt J. Lanz » Wed, 20 Aug 1997 04:00:00



> =
> hye,
> does anybody know how to get the current time & date settings ?
> I've tried using ctime(3), but i can't get it.
> thanks in advance,
> =
>                         julian.

A little more information as to how you "can't get it" would surely
get you a more informative response. Your post is the equivalent of
"my car won't start". =

-- =

Kurt J. Lanza


 
 
 

Getting current date and time.

Post by Bjorn Ree » Wed, 20 Aug 1997 04:00:00



> does anybody know how to get the current time & date settings ?
> I've tried using ctime(3), but i can't get it.

Use time(NULL) to obtain the current time.

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

int main(void)
{
  time_t now = time(NULL);
  char *text = ctime(&now);

  printf("Time is: %s", text);

  return 0;

Quote:}

 
 
 

Getting current date and time.

Post by Guy Harr » Wed, 20 Aug 1997 04:00:00



>does anybody know how to get the current time & date settings ?
>I've tried using ctime(3), but i can't get it.


Quote:>A little more information as to how you "can't get it" would surely
>get you a more informative response. Your post is the equivalent of
>"my car won't start".

Well, actually, given that he didn't also say "I've tried using time(2)"
or "I've tried using time(3v)" or "I've tried using gettimeofday(2)"
or..., it *might* be the case that his problem is that none of the
routines described in the "ctime" man page get the *current* date and
time settings - they just convert time and date values between different
formats.

The original poster should try using "time()" to get a "time_t" value
representing the current date/time, and then using the various routines
in the "ctime" man page to convert that to other formats as desired.

Then again, given that "ctime()" takes an argument, I would have
expected it to have been obvious that you can't use it to *get* the
current time and date settings, you can only use it to format a setting
you've *already gotten* into a string....
--
Reply, or follow up, but don't do both, please.



 
 
 

1. date/time of a file compare with current date/time

Hi,

I hope i can drop my question about Linux shell programming here?

I'm writing a script in bash to find files. I'm using the slocate
programm, which is being runned every hour using a cron job, to create
it's database.

Now i want to know how long it is ago that the database has been
recreated. Zo i need to check the date and time from that file and
compare it with the current date and time. I know there must be easy to
do but i can't find the trick to do it.

Maikel van Gorkom

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Xfree86 problems

3. run time date and syslog date/time conflict

4. 'shift' what does it ?

5. Awk and getting the current date

6. 2 monitors with X under Linux - ATI 8514/Ultra + SVGA

7. current date & time from Fortran

8. Kernel panic: not syncing discs

9. question obtain the current date and time on a UNIX system.

10. WANTED: C routine to return current date/time

11. How to Compare File Date to Current Date

12. Getting the current time

13. Date/time keeps getting adjusted?