Acessing the "time" Part of time_t Value

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

    Acessing the "time" Part of time_t Value

    How do I mask out all but the _time_ components of a time_t value?
    Specifically, I have the following:
    time_t wTime = 1226764757;
    I happen to know that this is November 16, 2008 @ 8:59:17, but I have
    many other such items from which I want to use only the _time_ portion
    (e.g. 8:59:17). How do I eliminate the "date" portions of either the
    time_t value or the number I assign to it? TIA
  • miso.liptak

    #2
    Re: Acessing the "time&quot ; Part of time_t Value

    On Nov 20, 8:03 am, mrc2...@cox.net (Mike Copeland) wrote:
       How do I mask out all but the _time_ components of a time_t value? 
    Specifically, I have the following:
            time_t wTime = 1226764757;
       I happen to know that this is November 16, 2008 @ 8:59:17, but I have
    many other such items from which I want to use only the _time_ portion
    (e.g. 8:59:17).  How do I eliminate the "date" portions of either the
    time_t value or the number I assign to it?  TIA
    Is number of seconds since midnight what you want? time(0) % 86400?
    m.

    Comment

    • Pete Becker

      #3
      Re: Acessing the "time&quot ; Part of time_t Value

      On 2008-11-20 02:03:33 -0500, mrc2323@cox.net (Mike Copeland) said:
      How do I mask out all but the _time_ components of a time_t value?
      Specifically, I have the following:
      time_t wTime = 1226764757;
      I happen to know that this is November 16, 2008 @ 8:59:17, but I have
      many other such items from which I want to use only the _time_ portion
      (e.g. 8:59:17). How do I eliminate the "date" portions of either the
      time_t value or the number I assign to it? TIA
      Use gmtime() or localtime() to convert it to a tm.

      --
      Pete
      Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
      Standard C++ Library Extensions: a Tutorial and Reference
      (www.petebecker.com/tr1book)

      Comment

      • Pete Becker

        #4
        Re: Acessing the "time&quot ; Part of time_t Value

        On 2008-11-20 02:56:08 -0500, "miso.lipta k" <miso.liptak@gm ail.comsaid:
        On Nov 20, 8:03 am, mrc2...@cox.net (Mike Copeland) wrote:
        >   How do I mask out all but the _time_ components of a time_t value?
         
        >Specifically , I have the following:
        >        time_t wTime = 1226764757;
        >   I happen to know that this is November 16, 2008 @ 8:59:17, but I h
        ave
        >many other such items from which I want to use only the _time_ portion
        >(e.g. 8:59:17).  How do I eliminate the "date" portions of either the
        >time_t value or the number I assign to it?  TIA
        >
        Is number of seconds since midnight what you want? time(0) % 86400?
        m.
        The requirement (from the C standard) is that time_t is an "arithmetic
        type capable of representing times ...". That's all. It doesn't have to
        represent seconds, nor does it have to be based on midnight.

        --
        Pete
        Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
        Standard C++ Library Extensions: a Tutorial and Reference
        (www.petebecker.com/tr1book)

        Comment

        • James Kanze

          #5
          Re: Acessing the &quot;time&quot ; Part of time_t Value

          On Nov 20, 8:56 am, "miso.lipta k" <miso.lip...@gm ail.comwrote:
          On Nov 20, 8:03 am, mrc2...@cox.net (Mike Copeland) wrote:
          How do I mask out all but the _time_ components of a time_t
          value? Specifically, I have the following:
          time_t wTime = 1226764757;
          I happen to know that this is November 16, 2008 @ 8:59:17,
          but I have many other such items from which I want to use
          only the _time_ portion (e.g. 8:59:17). How do I eliminate
          the "date" portions of either the time_t value or the number
          I assign to it? TIA
          Is number of seconds since midnight what you want? time(0) %
          86400?
          That depends on how precise and how portable you have to be.
          Not all days have exactly 86400 seconds, and time_t can be any
          numeric type, with any representation---if it uses the
          representation that was current in MS-DOS, your results are
          meaningless, and if it is a double, your solution won't even
          compile. (But for a lot of uses, it's adequate. It's what I
          currently do---but in my case, even if I'm a minute or so off,
          it's no big deal, and I only have to support
          Unix-likes---Solaris and Linux.)

          --
          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...