Acessing the "time" Part of time_t Value

M

Mike Copeland

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
 
M

miso.liptak

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

James Kanze

On Nov 20, 8:03 am, (e-mail address removed) (Mike Copeland) wrote:
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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top