home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18793 < prev    next >
Encoding:
Text File  |  1992-12-22  |  2.0 KB  |  74 lines

  1. Path: sparky!uunet!pipex!warwick!uknet!axion!gssec.bt.co.uk!awright
  2. From: awright@gssec.bt.co.uk (Alan Wright)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Need HELP with strptime....any answers/clues?????
  5. Message-ID: <1992Dec22.185309.15061@gssec.bt.co.uk>
  6. Date: 22 Dec 92 18:53:09 GMT
  7. References: <BzDJuA.AGF@sdf.lonestar.org> <BzH0Bs.K4J@news.cecer.army.mil> <1992Dec21.172542.28171@linus.mitre.org>
  8. Sender: usenet@gssec.bt.co.uk
  9. Organization: BT, Software Engineering Centre, Glasgow, UK
  10. Lines: 62
  11.  
  12. In article <1992Dec21.172542.28171@linus.mitre.org>,i
  13. jrv@mbunix.mitre.org (Van Zandt) writes:
  14. |> 
  15. |> >>I have been working with some of the time functions (on a Sun
  16. |> >>SPARCstation IPX).  After I make a call to strptime (to fill 
  17. |> >>in the tm structure) I display the structure (with dbxtool) and
  18. |> >>find that the structure is filled in incorrectly.  What am I 
  19. |> >>doing wrong?
  20. |> ...
  21. |> >>    struct    tm    *my_tm;
  22. |> >> 
  23. |> >>    (void)strptime(timeString,"%Y,%j/%H%M%S",my_tm);
  24. |> 
  25. |> my_tm needs to be initialized to point to a struct tm before
  26. |> asking strptime to fill it in.
  27. |> 
  28. |>                    - Jim Van Zandt <jrv@mitre.org>
  29.  
  30. I had problems with strptime on the Sun a few months ago and
  31. came to the conclusion that it was broken. Are you saying that
  32. the following should work?
  33.  
  34. #include <sys/types.h>
  35. #include <sys/time.h>
  36. #include <time.h>
  37. #include <ctype.h>
  38. #include <stdio.h>
  39.  
  40. main()
  41. {
  42.    static char *s = "19920901111500";
  43.    struct tm *tm;
  44.    time_t tloc;
  45.  
  46.    time(&tloc);
  47.    tm = localtime(&tloc);
  48.    strptime(s, "%Y%m%d%H%M%S", tm);
  49.    tloc = timelocal(tm);
  50.  
  51.    printf("Converted %s to %s, tloc = %ld\n",
  52.       s, ctime(&tloc), tloc);
  53. }
  54.  
  55. I have also tried:
  56.  
  57. int main()
  58. {
  59.    static char *s = "19920901111500";
  60.    struct tm tm;
  61.    time_t tloc;
  62.  
  63.    strptime(s, "%Y%m%d%H%M%S", &tm);
  64.    tloc = timelocal(&tm);
  65.    ...
  66.  
  67. No matter how I twist things it always fails.
  68.  
  69. -- Alan.
  70. --------------------------------------------
  71. awright@gssec.bt.co.uk (Alan Wright)
  72. BT, Software Engineering Centre, Glasgow, UK
  73. --------------------------------------------
  74.