473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
Nov 20 '08 #1
4 3477
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.
Nov 20 '08 #2
On 2008-11-20 02:03:33 -0500, mr*****@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)

Nov 20 '08 #3
On 2008-11-20 02:56:08 -0500, "miso.liptak" <mi*********@gmail.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)

Nov 20 '08 #4
On Nov 20, 8:56 am, "miso.liptak" <miso.lip...@gmail.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:ja*********@gmail.com
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

Nov 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: a_geek | last post by:
Hello, I'm writing a small program that needs to check Unix timestamps for falling into an interval (typical usage: ./program 2005-03, you get the idea). Now, I create two time stamps from the...
2
by: New Guy | last post by:
Hello, First, I want to apologize for posting this message to multiple groups. (1) I have a hard time finding any info and (2) this is not a school assignment. I am trying to create in my...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
9
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
3
by: Reney | last post by:
I am using Access Database in my program. The column in the table that I am going to use has date/time value with Medium Time selected. (HH:mm). The program is recording a clock in time to this...
2
by: Micah Williamson | last post by:
Does anyone know how to make it so that a time entered as a string, and stored in a string record in an access 2000 database can be kept as a string? When ever I enter a time like 1:00:00 PM...
17
by: teddysnips | last post by:
One of my clients has asked me to make a change to one of their Access applications. The application is a Front End/Back End standard app. I didn't develop it, but looking at it tells me that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.