472,805 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 3441
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: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.