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

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

Post by Niranjan Pere » Wed, 13 Sep 1995 04:00:00



Hi:

How does one obtain the current date and time on a UNIX system from inside a C
program ?

  gettimeofday(struct timeval *, struct timezone *);

gives me the  time since the start of the epoch. Is there a easier way to
obtain the current system time like date(1) does ?

Thanks,

-- Niranjan

 
 
 

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

Post by Mahesh Khilna » Wed, 13 Sep 1995 04:00:00



> Hi:

> How does one obtain the current date and time on a UNIX system from inside a C
> program ?

>   gettimeofday(struct timeval *, struct timezone *);

> gives me the  time since the start of the epoch. Is there a easier way to
> obtain the current system time like date(1) does ?

> Thanks,

check man localtime(). This is the basic call, and the man page
should list variants and formaters.

--Mahesh

Quote:

> -- Niranjan


 
 
 

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

Post by Joe Foster of Bo » Wed, 13 Sep 1995 04:00:00



> Hi:
> How does one obtain the current date and time on a UNIX system from inside a C
> program ?
>   gettimeofday(struct timeval *, struct timezone *);
> gives me the  time since the start of the epoch. Is there a easier way to
> obtain the current system time like date(1) does ?
> Thanks,
> -- Niranjan

You can use the time() function to get the number of seconds
since the epoch and pass that value to ctime() to get a string.

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!

 
 
 

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

Post by Niranjan Pere » Thu, 14 Sep 1995 04:00:00



>Hi:
>How does one obtain the current date and time on a UNIX system from inside a C
>program ?
>  gettimeofday(struct timeval *, struct timezone *);
>gives me the  time since the start of the epoch. Is there a easier way to
>obtain the current system time like date(1) does ?
>Thanks,
>-- Niranjan

Thanks to the folk who replied. The solution was to use

#include<time.h>
time_t t = time(0);
printf("%s"ctime(&t));

-- Niranjan

 
 
 

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

Post by Nigel Wade,Physics,3568 » Tue, 19 Sep 1995 04:00:00




Quote:>Hi:

>How does one obtain the current date and time on a UNIX system from inside a C
>program ?

>  gettimeofday(struct timeval *, struct timezone *);

>gives me the  time since the start of the epoch. Is there a easier way to
>obtain the current system time like date(1) does ?

>Thanks,

>-- Niranjan

If you are on a SVR4 system have a look at the ctime(3) manual page.

This has all the routines to get the current date/time in a variety of
formats.

I don't know if this is available on other systems, but have a look for it
anyway, you might be lucky.

--
Nigel Wade, System Administrator, Ionospheric Physics Group,
            University of Leicester, Leicester, LE1 7RH, UK

Phone :     +44 (0)116 2523568, Fax : +44 (0)116 2523555

 
 
 

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

Post by Mingyu Hua » Fri, 22 Sep 1995 04:00:00




: >Hi:
: >
: >How does one obtain the current date and time on a UNIX system from inside a C
: >program ?
: >
: >  gettimeofday(struct timeval *, struct timezone *);
: >
: >gives me the  time since the start of the epoch. Is there a easier way to
: >obtain the current system time like date(1) does ?
: >
: >Thanks,
: >
: >-- Niranjan
: >

: If you are on a SVR4 system have a look at the ctime(3) manual page.

: This has all the routines to get the current date/time in a variety of
: formats.

: I don't know if this is available on other systems, but have a look for it
: anyway, you might be lucky.

: --
: Nigel Wade, System Administrator, Ionospheric Physics Group,
:             University of Leicester, Leicester, LE1 7RH, UK

: Phone :     +44 (0)116 2523568, Fax : +44 (0)116 2523555

 
 
 

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. bad c++ library archive

3. System date and file dates not showing in same time zone

4. RH6.1 hangs when I logoff if I am connected via PPP

5. Unix system g77 calls DATE and TIME not working for Alpha/Linux

6. network card

7. run time date and syslog date/time conflict

8. Help -> inode table

9. SIMS date and time is not matching with system time

10. How to convert time/date info into unix clock time

11. converting date and time to unix time

12. ??? UNIX tick time of future or past date/time

13. current date & time from Fortran