Working with Time Data (I think...)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Copeland

    Working with Time Data (I think...)

    I am working with a file of data that contains "time values" (e.g.
    "1225365563 "), and I want to convert this data into something I can use
    in a program I'm developing. From what I've read about time_t, it seems
    this value, if converted from its string format, would be a date/time
    value - if I could convert it. I find no conversion function that will
    do anything for me, so I'm asking what I might do. Any thoughts? TIA
  • maverik

    #2
    Re: Working with Time Data (I think...)

    On Nov 10, 8:27 pm, mrc2...@cox.net (Mike Copeland) wrote:
       I am working with a file of data that contains "time values" (e.g.
    "1225365563 "), and I want to convert this data into something I can use
    in a program I'm developing.  From what I've read about time_t, it seems
    this value, if converted from its string format, would be a date/time
    value - if I could convert it.  I find no conversion function that will
    do anything for me, so I'm asking what I might do.  Any thoughts?  TIA
    First that I think:
    do scanf("... %ld ...") (or scanf("... %d ...") or any other integer
    type because of 7.23.1 of c99 standard)
    and you get value you need (you can cast it to the time_t if you want)

    Comment

    • maverik

      #3
      Re: Working with Time Data (I think...)

      On Nov 10, 8:43 pm, maverik <maverik.m...@g mail.comwrote:
      First that I think:
       do scanf("... %ld ...") (or scanf("... %d ...") or any other integer
      type because of 7.23.1 of c99 standard)
       and you get value you need (you can cast it to the time_t if you want)
      You can play with time_t using difftime, strftime, strptime, ctime,
      asctime, localtime, ...

      Comment

      • maverik

        #4
        Re: Working with Time Data (I think...)

        On Nov 10, 8:43 pm, maverik <maverik.m...@g mail.comwrote:
        First that I think:
         do scanf("... %ld ...") (or scanf("... %d ...") or any other integer
        Ups, I'm in the c++ thread. You can use
        std::ifstream to read value you need from file or any other stl/
        boost/... method (for complex syntax of the file it's better to use
        boost::spirit or some C++ compiler compiler or write parser by
        yourself).


        Comment

        • Obnoxious User

          #5
          Re: Working with Time Data (I think...)

          On Mon, 10 Nov 2008 10:27:29 -0700, Mike Copeland wrote:
          I am working with a file of data that contains "time values" (e.g.
          "1225365563 "), and I want to convert this data into something I can use
          in a program I'm developing. From what I've read about time_t, it seems
          this value, if converted from its string format, would be a date/time
          value - if I could convert it. I find no conversion function that will
          do anything for me, so I'm asking what I might do. Any thoughts? TIA




          --
          OU
          Remember 18th of June 2008, Democracy died that afternoon.

          Comment

          • Mike Copeland

            #6
            Re: Working with Time Data (I think...)

            I am working with a file of data that contains "time values" (e.g.
            "1225365563 "), and I want to convert this data into something I can use
            in a program I'm developing. From what I've read about time_t, it seems
            this value, if converted from its string format, would be a date/time
            value - if I could convert it. I find no conversion function that will
            do anything for me, so I'm asking what I might do. Any thoughts? TIA
            >
            http://www.cplusplus.com/reference/clibrary/ctime/
            Yes, I had already found that link. However, already having the data
            string, I didn't know how to move/convert it into a time_t variable to
            use those functions. Maverik's answer showed me how to do it (sscanf),
            and I now can use some of those functions. Thanks...

            Comment

            • James Kanze

              #7
              Re: Working with Time Data (I think...)

              On Nov 10, 6:27 pm, mrc2...@cox.net (Mike Copeland) wrote:
                 I am working with a file of data that contains "time values" (e.g.
              "1225365563 "), and I want to convert this data into something I can use
              in a program I'm developing.  From what I've read about time_t, it seems
              this value, if converted from its string format, would be a date/time
              value - if I could convert it.  I find no conversion function that will
              do anything for me, so I'm asking what I might do.  Any thoughts?  TIA
              The first question is: what do these data actually contain. In
              C++ (like in C), time_t is a sort of a vague hack used to
              contain dates, times or date-times, depending on the
              application. Portably, they're data-times; Posix guarantees
              more, and I seem to recall that Windows conforms more or less to
              what Posix requires here (but I'm not sure), so you may be able
              to count on it being an integral type containing a value in
              seconds from some given date and time (often midnight, 1 Jan,
              1970, GMT on Unix machines). Given that:

              -- For times, the general convention is to use a time in the
              date 1 Jan 1970 (or whatever the cutoff date is, provided
              that the cutoff date-time has a time of midnight).

              -- For dates, the general convention is to use midnight of the
              date in question.

              Given that, you know that there are either 24*60*60 or
              24*60*60+1 seconds in a day. The latter is rare enough that
              in most applications, you can ignore it, so you can use the /, %
              and * operators to force any given value to be a date or a time,
              or the + operator to combine a date and a time into a date-time.

              All of this, of course, for whatever timezone your system uses.
              (GMT for most, if not all Unix---I'm lucky in that we need all
              our dates and times in GMT anyway, so it works for me:-).)

              --
              James Kanze (GABI Software) email:james.kan ze@gmail.com
              Conseils en informatique orientée objet/
              Beratung in objektorientier ter Datenverarbeitu ng
              9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

              Comment

              Working...