473,795 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3506
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.lipta k" <mi*********@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)

Nov 20 '08 #4
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:ja******* **@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

Nov 20 '08 #5

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

Similar topics

1
1460
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 user's input to create the interval's borders using mktime(). Trying to check the sanity of my program, I also converted the values back to tuples using localtime(). Unfortunately, I get back one of them with the DST flag set, and the other with...
2
5099
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 Oracle test database a "time" table that would have time buckets. What I mean is that, it would have some structure like this
16
10514
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 using C# eg. - String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from the database. - I do not care about the time portion, I only want "1/1/2005" for display.
9
6023
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 localtime_r and asctime_r where I was using localtime and asctime. But I didn't find any correspondent _r function to "time".Also, I found that "readdir" is not thread safe. But what about "scandir"? Thanks for any help
3
11733
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 field, which is the time when the entry is made. If you check the database, it shows the correct time in the correct format. But when you are calling it with a dataset and showing with a datagrid, it doesn't show the time value but it always shows...
2
3061
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 into a bound text box, then I update the access database, the value changes to a date with time attached. Access then takes the time portion away, and only leaves the date. The dataset recognizes the field in the database as text,
17
3923
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 it was done entirely using the Wizards. There is no log-in procedure. They want to amend it so that only one person can be logged in at any one time. So, if Joe Bloggs tries to open the application, and Fred Jones has already connected, Joe...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10438
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.