Acessing the "time" Part of time_t Value

Discussion in 'C++' started by Mike Copeland, Nov 20, 2008.

  1. 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
     
    Mike Copeland, Nov 20, 2008
    #1
    1. Advertising

  2. Mike Copeland

    miso.liptak Guest

    On Nov 20, 8:03 am, (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.
     
    miso.liptak, Nov 20, 2008
    #2
    1. Advertising

  3. Mike Copeland

    James Kanze Guest

    On Nov 20, 8:56 am, "miso.liptak" <> wrote:
    > On Nov 20, 8:03 am, (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:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Nov 20, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HMS Surprise

    Convert date & time to time_t

    HMS Surprise, May 16, 2005, in forum: C Programming
    Replies:
    1
    Views:
    625
    Gordon Burditt
    May 16, 2005
  2. Sven
    Replies:
    18
    Views:
    949
    Chris Torek
    Aug 20, 2006
  3. baumann@pan
    Replies:
    2
    Views:
    598
    baumann@pan
    Jan 22, 2007
  4. Henrik Goldman

    Reading local time into time_t

    Henrik Goldman, Mar 26, 2006, in forum: C++
    Replies:
    8
    Views:
    728
    Marcus Kwok
    Mar 28, 2006
  5. saurabh

    time issue (mktime time_t tm)

    saurabh, Apr 14, 2009, in forum: C Programming
    Replies:
    3
    Views:
    1,862
Loading...

Share This Page