stat->st_atime converted to a meaningfull date/time

stat->st_atime converted to a meaningfull date/time

Post by Rocke Robertso » Wed, 07 Mar 2001 15:40:59



time_t secs;
snip>
secs=statbuf->st_atime * 86400;  <-- This is likely wrong.
        fprintf(stderr,"st_atime %d\n", statbuf->st_atime);
        strftime(line,MAXLINE,"%Y-%m-%d",gmtime(&secs));
        fprintf(stderr,"value of atime %s\n",line);

when I print out the value of line, it dumps core. What the heck am I
doing wrong. I want to do this for ctime and mtime as well.
TIA

--
==========================================
Rocke Robertson
PWGSC-GTIS-CPS
Voice (613) 748-4604
Fax   (613) 748-4843

==========================================

 
 
 

stat->st_atime converted to a meaningfull date/time

Post by Andrew Giert » Wed, 07 Mar 2001 03:50:32


 Rocke> time_t secs;
 [...]
 Rocke> secs=statbuf->st_atime * 86400;  <-- This is likely wrong.

yes, it's wrong. st_atime is already a time_t.

 Rocke>         fprintf(stderr,"st_atime %d\n", statbuf->st_atime);
 Rocke>         strftime(line,MAXLINE,"%Y-%m-%d",gmtime(&secs));
 Rocke>         fprintf(stderr,"value of atime %s\n",line);

 Rocke> when I print out the value of line, it dumps core.

where and how are you declaring "line"?

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

stat->st_atime converted to a meaningfull date/time

Post by John Gord » Wed, 07 Mar 2001 04:24:58



> time_t secs;
> snip>
> secs=statbuf->st_atime * 86400;  <-- This is likely wrong.

yes it is.  what are you trying to achive?  statbuf->st_atime is
already a time_t object.  just use it.

(i'm assuing that you've allocated statbuf correctly.  have you?)

Quote:>         fprintf(stderr,"st_atime %d\n", statbuf->st_atime);
>         strftime(line,MAXLINE,"%Y-%m-%d",gmtime(&secs));
>         fprintf(stderr,"value of atime %s\n",line);
> when I print out the value of line, it dumps core. What the heck am I
> doing wrong. I want to do this for ctime and mtime as well.
> TIA

are you sure that it's dumping core on the printf() and not the strftime?

---
"... What with you being his parents and all, I think that you could
be trusted not to shaft him."  -- Robert Chang, rec.games.board


 
 
 

stat->st_atime converted to a meaningfull date/time

Post by Rocke Robertso » Wed, 07 Mar 2001 16:25:25


I see. All I need is:

secs=statbuf->st_atime;
strftime(line,MAXLINE,"%Y-%m-%d",gmtime(&secs));
fprintf(stderr,"value of atime %s\n",line);

How does one know if something is in time_t format or not...?



>  Rocke> time_t secs;
>  [...]
>  Rocke> secs=statbuf->st_atime * 86400;  <-- This is likely wrong.

> yes, it's wrong. st_atime is already a time_t.

>  Rocke>         fprintf(stderr,"st_atime %d\n", statbuf->st_atime);
>  Rocke>         strftime(line,MAXLINE,"%Y-%m-%d",gmtime(&secs));
>  Rocke>         fprintf(stderr,"value of atime %s\n",line);

>  Rocke> when I print out the value of line, it dumps core.

> where and how are you declaring "line"?

> --
> Andrew.

> comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
>                            or <URL: http://www.whitefang.com/unix/>

--
==========================================
Rocke Robertson
PWGSC-GTIS-CPS
Voice (613) 748-4604
Fax   (613) 748-4843

==========================================
 
 
 

stat->st_atime converted to a meaningfull date/time

Post by John Gord » Wed, 07 Mar 2001 04:34:18



> I see. All I need is:
> secs=statbuf->st_atime;
> strftime(line,MAXLINE,"%Y-%m-%d",gmtime(&secs));
> fprintf(stderr,"value of atime %s\n",line);
> How does one know if something is in time_t format or not...?

by reading the man page on the stat command.

---
"... What with you being his parents and all, I think that you could
be trusted not to shaft him."  -- Robert Chang, rec.games.board


 
 
 

1. iu: convert date&time (local-->UT)

hello,
    I try to make a fonction to convert a local time in UT time. i try to
use
     mktime + gmtime + timezone + daylight.... but the result is bad.
    Please help me....
    The problem is the same when i try to convert a UT time in Local
Time....
    my imput date format is : 'YYYYMMDDHHMMSS'.

    Does anyone know about a function or an example (in C) .
    Thanks for any help.

2. Need Contact Database Software

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

4. doscmd & vga (raw mode)

5. converting date and time to unix time

6. 3com 3c905 support under Linux?

7. stat() and st_atime - Solaris 2.5

8. coyote linux

9. Converting date returned by stat

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

11. run time date and syslog date/time conflict

12. convert UT time in local time / local time in UT time

13. Converting STAT Time to String